Angular JS:动态加载 CSS 和 JS 文件 [英] Angular JS: Load CSS and JS files dynamically
问题描述
我正在开发一个网络应用程序.我正在使用 AngularJS 将所有文件动态加载到 UI 中.
I am in the middle of developing a web app. I am using AngularJS for loading all the files dynamically into the UI.
我有一个 index.html
文件,所有文件都将在点击或加载时动态加载到其中.
I have an index.html
file into which all the files will be loaded dynamically on-click or on-load.
//index.html
<signin button> <signup button> // etc.,
//on-clicking signin button a SignIn-page will load in the below div
<div id="bodyview"></div>
// end of index.html
现在我的登录页面看起来有点像下面的结构
Now my sign-in page looks somewhat like the below structure
/*a div where my accordion menu will load when the
*below submit button is clicked*/
<div id="menu"></div>
//other sign-in-form stuff will follow on...
//submit button at the end
<submit button> //only on clicking the submit button the menu will be loaded
现在我的问题是,虽然我能够加载手风琴 menu.html 文件,但我无法加载它所依赖的 css 和 js 文件.我研究过 stackoverflow,但没有一个对我有用.
Now my problem is, though I'm able to load the accordion menu.html file, I'm not able to load the css and js files it is dependent on. I have researched on stackoverflow but none worked for me.
任何人都可以帮忙确定一种使用 AngularJS 加载 css 和 js 依赖项的方法
Can anybody please help in determining a way for loading the css and js dependencies using AngularJS
推荐答案
只需编写一个服务,将 CSS 和 JS 文件添加到
Just write a service to add CSS and JS files to the <head>
这里是一个示例服务,用于动态加载 CSS 文件.您可以轻松修改它以加载 JS 文件.
Here is a example service which is used to dynamically load CSS files.You can modify it easily to load JS files.
https://github.com/Yappli/angular-css-injector
这篇关于Angular JS:动态加载 CSS 和 JS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!