Initialization of Angular. js basic learning and angular. js Initialization
I. Bind initialization and automatic loading
Through Binding to initialize angular, js Code will be infiltrated into html.
ng-app
Is an angular command, representing an angular application (also called a module ). Useng-app
Orng-app=""
To mark a DOM node so that the framework will automatically load the node. That is to say,ng-app
It can contain attribute values.
<body ng-app="myApp"> <div ng-controller="myCtrl"> {{ hello }} </div> <script type="text/javascript"> var myModule = angular.module("myApp",[]); myModule.controller("myCtrl",function($scope){ $scope.hello = "hello,angular!"; }); </script></body>
Ii. Manual Initialization
If you want to have more control over initialization, you can use a custom manual Bootstrap Method to initialize instead of angular's automatic initialization. For example, you need to do something before angular compiles the template, for example, changing the template content.
Angular also provides manually bound api -- bootstrap, which is used as follows:
angular.bootstrap(element, [modules], [config]);
The first parameterelement:
Yesng-app
Dom element;
- Modules: name of the bound Module
- Config: Additional configuration
It is worth noting that:
angular.bootstrap
Only the objects loaded for the first time will be bound.
- Duplicate binding or binding of other objects will be prompted on the console.
<Html>
Summary
The above is about angular. I hope the content in this article can be learned or used by you. js can provide some help. If you have any questions, you can leave a message. Thank you for your support.