ANJULARJS series 5--scopes, module, controller

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.