Does AngularJS support AMD like RequireJS?

前端 未结 3 1629
自闭症患者
自闭症患者 2020-12-14 17:53

In this repo AngularJS is implimented with RequireJS for AMD.

In this repo the AngularJS team seeds an AngularJS project with AMD that does not include Requ

3条回答
  •  被撕碎了的回忆
    2020-12-14 18:38

    You can lazy load Angular.js components using providers. From the article:

    Providers are essentially objects that are used to create and configure instances of AngularJS artefacts. Hence, in order to register a lazy controller, you would use the $controllerProvider. ...

    In summary, you would first define your app module to keep instances of the relevant providers. Then you would define your lazy artefacts to register themselves using the providers rather than the module API. Then using a ‘resolve’ function that returns a promise in your route definition, you would load all lazy artefacts and resolve the promise once they have been loaded. This ensures that all lazy artefacts will be available before the relevant route is rendered. Also, don’t forget to resolve the promise inside $rootScope.$apply, if the resolution will be happening outside of AngularJS. Then you would create a ‘bootstrap’ script that first loads the app module before bootstrapping the app. Finally, you would link to the bootstrap script from your ‘index.html’ file.

    http://ify.io/lazy-loading-in-angularjs/

提交回复
热议问题