1. Caution Points during controller use
- Do not attempt to re-use the controller, a director is generally responsible for a small piece of view
- Do not manipulate the DOM in the controller, which is not the responsibility of the controllers. Encapsulated in instructions.
- Do not format the data in the controller, NG has a very useful form control
- Do not do data filtering operations in controller, NG has $filter service
- In general, controllers do not call each other , and interactions between controller are---by events > this is strongly coupled
2.
<HTMLNg-app> <Div> <inputNg-model= "Greeting.Text"/> <P>{{Greeting.Text}}, Angular</P> </Div> .... <Scriptsrc= "Js/angular-1.3.0.js"></Script><HTML>
The value in the P tag is changed as input in input.
After starting, you will find the instructions in Ng-app. When Ng-model is found, the Greeting.Text data model is generated, which mounts the scope root so that all {{Greeting.Text}} can get its value
3. ANGULARJS MVC is implemented with the help of $scope
The scope is also hierarchical, and if no value is found in the inner scope, it will look up, similar to the prototype found in JS
4. About $scope
- $scope is a pojo (Plain old JavaScript Object)
- $scope provides some tool methods $watch ()/$apply ()
- $scope is the execution environment (or scope) of an expression
- $scope is a tree structure, parallel to the DOM tag
- The child $scope object inherits the properties and methods on the parent $scope
- Each angular application has only one root $scope object (typically located on Ng-app)
- $scope can propagate events, like DOM events, which can be down or up
- $scope is not only the basis of MVC, but also the basis for implementing bidirectional data binding later.
- Can be debugged with angular.element ($). Scope ()
- $scope life cycle: Creation->watcher Registration->model mutation->mutation observation->scope Destruction
Angularjs Study Notes (Mu-class web)