the world of views and $scope
Angularjs starts and generates a view, binding Ng-app with $rootscope. $rootScope is the top level of all $scope objects. Corresponds to the global scope of a ng-app. $scope object acts only as a data model, without processing and manipulating data.
The following is an example of $rootscope:
<!DOCTYPE HTML><HTML> <Head> <Scriptsrc= "Angularjs/1.2.13/angular.js"></Script> </Head> <BodyNg-app= "MYAPP"> <Div>Hello {{name}}</Div> </Body> <Script> varapp=Angular.module ('myApp', []). Run (function($rootScope) {$rootScope. Name=" World"; }); </Script></HTML>
The above example sets a name variable in $rootscope and references it. To avoid polluting the global namespace, you can explicitly create an isolated $scope object with the controller, and then set the variable to this sub-variable. You can attach a controller object to a DOM element by using the Ng-controller directive. As follows:
<!DOCTYPE HTML><HTML> <Head> <Scriptsrc= "Angularjs/1.2.13/angular.js"></Script> </Head> <BodyNg-app= "MYAPP"> <DivNg-controller= "Mycontroller">Hello {{name}}</Div> </Body> <Script> varapp=Angular.module ('myApp', []); App.controller ("Mycontroller",function($scope) {$scope. Name="Ari"; }) </Script></HTML>the life cycle of the $scope
1. Create
When you create a controller or instruction, $injector create a new scope and pass the scope in when the new controller or instruction runs.
2. Links
When angular starts running, all $scope objects are attached to the view.
3. Update
When an event loop runs, the top-level $scope object is typically executed, and each child scope performs its own dirty-value detection. When a transform is detected, the specified callback function is triggered.
4. Destruction
directives and Scopes
Directives typically do not create their own scopes, but the Ng-controller and ng-repeat directives create their own scopes.
4th Chapter Scope