Fifth article, scopes, module, controller
This article, feeling, in the previous several used properties, but, always feel no understanding thoroughly, to be perfected! ~
1, scopes
A, definition: $scope is an object that links a view (a DOM element) to a controller
B, explain: $scope is actually a JavaScript object, controller and view can access it, so we can use it to pass information between the two.
In this $scope object, we store both the data and the functions that will run on the view.
C, $rootScope
Every angular application will have a $rootScope.
This $rootScope is the top-level scope, which corresponds to the DOM element that contains the Ng-app Directive attribute.
Values defined with Rootscope can be used in individual controllers or assigned to scope.
2. Module
One more attribute on the
In JS, we call the Angular object's module method to declare a module whose name corresponds to the value of the Ng-app. This statement will allow NG to run.
Example:
var demoApp = angular.module (' demoApp ', []);
3. Controller
The Ng-controller directive creates a new $scope object for the DOM element in which it resides.
<div ng-controller= "Mycontroller" > {{person.name}} </div>
ANJULARJS series 5--scopes, module, controller