Angular JS:动态加载CSS和JS文件

Roo*_*opa 14 angularjs angular-ui angularjs-directive angularjs-scope

我正在开发一个Web应用程序.我正在使用AngularJS将所有文件动态加载到UI中.
1.我有和index.html所有文件将在点击或加载时动态加载.

//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
Run Code Online (Sandbox Code Playgroud)

现在我的登录页面看起来有点像下面的结构

    /*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
Run Code Online (Sandbox Code Playgroud)

现在我的问题是,虽然我能够加载手风琴menu.html文件,但我无法加载它所依赖的css和js文件.我已经调查了大多数stackoverflow讨论和许多其他的..但没有一个对我有用.
任何人都可以帮助确定使用Angular JS加载css和js依赖项的方法吗?
任何帮助表示赞赏.提前致谢

rpp*_*pig 19

只需编写一个服务来添加CSS和JS文件 <head>

这是一个用于动态加载CSS文件的示例服务.您可以轻松修改它以加载JS文件.

https://github.com/Yappli/angular-css-injector

  • 这可以用来注入JS文件吗? (2认同)

Olg*_*nko 7

目前我使用angular-css:https://github.com/door3/angular-css Imho,它是目前最好,最灵活的解决方案之一.