Load scripts through all components in Angular 2

前端 未结 2 1056
终归单人心
终归单人心 2021-01-07 02:09

I have been using Angular 2 with AdminLTE which needs to run some scripts to load properly. So I have added them in in my .anglular-cli.json:



        
2条回答
  •  佛祖请我去吃肉
    2021-01-07 02:51

    You can remove and recreate your script elements in DOM every time you need, like this:

    document.getElementById("myScript").remove();
    var testScript = document.createElement("script");
    testScript.setAttribute("id", "myScript");
    testScript.setAttribute("src", "assets/js/script.js");
    document.body.appendChild(myScript);
    

    I posted a question in GitHub where I explain how to do it.

提交回复
热议问题