简体   繁体   中英

Load Angular scripts on demand

I have an application that must register Angular new Controllers obtained from a script. It should be able to charge the minimum amount of script to start the application and then obtain the necessary scripts on demand from other modules.

For instance:

  • The application is loaded.
  • A menu is displayed.
  • After clicked on an item, it verifies that the module is not loaded, then the scripts are obtained through an http request.
  • By getting the scripts must register all Controllers / Services to all urls of the new module will be available.

You could use AngularJs manual bootstrap.

Below is an example from AngularJs document:

<!doctype html>
<html>
<body>
<div ng-controller="MyController">
   Hello {{greetMe}}!
</div>
<script src="http://code.angularjs.org/snapshot/angular.js"></script>

<script>
angular.module('myApp', [])
  .controller('MyController', ['$scope', function ($scope) {
    $scope.greetMe = 'World';
  }]);

angular.element(document).ready(function() {
  angular.bootstrap(document, ['myApp']);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM