Read Catalogue
- Binding initialization
- Manual initialization
For the average consumer, Angularjs's Ng-app are manually bound to a DOM element. But in some applications, this is very inconvenient.
Go back to the top of the binding initialization
By binding to the initialization of angular, JS code will be hacked into the HTML, but for the novice use, still enough!
<HTML><Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <Scriptsrc= "Http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></Script></Head><BodyNg-app= "MYAPP"> <DivNg-controller= "Myctrl">{{Hello}}</Div> <Scripttype= "Text/javascript"> varMyModule=Angular.module ("myApp",[]); Mymodule.controller ("Myctrl",function($scope) {$scope. Hello= "hello,angular!"; }); </Script></Body></HTML>
When it is run, it displays
hello,angular!
Back to top manual initialization
Manual binding of the Api--bootstrap is also available in angular, which is used in the following ways:
angular.bootstrap(element, [modules], [config]);
The first parameter, element, is the DOM element that binds Ng-app;
Modules: The module name of the binding
Config: Additional configuration
Simply look at the code:
<HTML> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <Scriptsrc= "Http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></Script><BodyID= "Body"> <DivNg-controller= "Myctrl">{{Hello}}</Div> <Scripttype= "Text/javascript"> varapp=Angular.module ("bootstraptest",[]); App.controller ("Myctrl",function($scope) {$scope. Hello= "Hello,angular from Bootstrap"; }); //Angular.bootstrap (document.getElementById ("Body"), [' bootstraptest ']);Angular.bootstrap (document,['bootstraptest']); </Script></Body></HTML>
It is worth noting that:
- Angular.bootstrap only binds objects that are loaded for the first time.
- Subsequent repeated bindings or bindings to other objects will output error prompts at the console.
AngularJS API Bootstrap startup