In angular-cli, how does the “lazy” attribute work to load global libraries?

后端 未结 2 1244
后悔当初
后悔当初 2021-01-06 05:38

By adding them to the scripts property of .angular-cli file, one can load global scripts into your app. This example comes from the documentation:

\         


        
2条回答
  •  一生所求
    2021-01-06 05:41

    As an alternative to manipulating the DOM in step #2 of Will Huang's accepted answer, it's now also possible to use the dynamic import functionality of esnext with TypeScript, as outlined in this post.

    Using this approach, one could then add the following to a lazy-loaded NgModule:

    import('jquery')
        .then((module: Function) => {
            window['$'] = module;
        });
    

提交回复
热议问题