Angular JS:動態加載CSS和JS文件 - Angular JS: Load CSS and JS files dynamically -开发者知识库

Angular JS:動態加載CSS和JS文件 - Angular JS: Load CSS and JS files dynamically -开发者知识库,第1张

I am in the middle of developing an web app. I am using AngularJS for loading all the files dynamically into the UI.
1. i have and index.html onto which all the files will be loaded dynamically on click or on load.

我正在開發一個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

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

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 looked into most of the stackoverflow discussions and many others.. but none worked for me.
Can anybody please help in determining a way for loading the css and js dependencies using Angular JS...?
Any Help is appreciated. Thanks in advance

現在我的問題是,雖然我能夠加載手風琴menu.html文件,但我無法加載它所依賴的css和js文件。我已經調查了大多數stackoverflow討論和許多其他人......但沒有一個對我有用。任何人都可以幫助確定使用Angular JS加載css和js依賴項的方法嗎?任何幫助表示贊賞。提前致謝

4 个解决方案

#1


18  

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.

這是一個用於動態加載CSS文件的示例服務。您可以輕松修改它以加載JS文件。

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

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

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复