Preface
As we all know, in traditional angularJS applications, angular applications are bound to a certain dom through ng-app. This will invade the js code to the html. angular provides a manually started API-()
。
This article will introduce to you the relevant content on the automatic and manual binding of the ng-app init, and share it for your reference and learning. I won’t say much about it below, let’s take a look at the detailed introduction together.
1. Traditional binding initialization
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="/libs//1.2.16/"></script> </head> <body ng-app="myApp"> <div ng-controller="myCtrl"> {{ hello }} </div> <script type="text/javascript"> var myModule = ("myApp",[]); ("myCtrl",function($scope){ $ = "hello,angular!"; }); </script> </body> </html>
2. Manual initialization
(element, [appName], [config]);
- element: bind ng-app's dom element
- modules: bound module name
- config: Additional configuration
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="/libs//1.2.16/"></script> <body > <div ng-controller="myCtrl"> {{ hello }} </div> <script type="text/javascript"> var app = ("bootstrapTest",[]); ("myCtrl",function($scope){ $ = "hello,angular from bootstrap"; }); // (("body"),['bootstrapTest']); (document,['bootstrapTest']); // Each html loaded by the browser will correspond to a document object. This object is the root node of all dom elements in html and also belongs to the dom element. </script> </body> </html>
Notice: Only the object loaded for the first time will be bound. The subsequent repeated bindings or other objects will be bound to the console.
Summarize
The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.