Angularjs Getting Started

Source: Internet
Author: User

Basic knowledge: http://www.runoob.com/angularjs/angularjs-tutorial.html

Download Angularjs website: http://www.bootcdn.cn/angular.js/

ANGULARJS Concept:

1.MVC

Encapsulated data Code (model), Application logic code (Controller), page rendering data code (view), three-layer independent separation

Angular, the view is the Documenet object model, the controller is the JavaScript class, the data model is stored in the object's properties

2. Data binding

Data binding automatically synchronizes the data between model and view, and angular implements data binding by the model as the data source, the view is always the model's projection, and when the model is changed, it is automatically reflected on the view

3. Dependency Injection

Angular's dependency injection is to get what it needs without creating what they depend on (a word---> nothing you don't come to me, I'll come to you. )

4.Angular Data Binding principle: Use dirty checks to compare whether data has changed

There are two general cases of knowing that a variable is changed

(1) One is to change the value through a fixed interface, such as the set () method, the disadvantage is cumbersome, each property to write a set method,

(2) Two is a dirty check, the object copy a snapshot, at some time compared to the object and snapshot values, if not the same as the description has changed, this strategy to keep two parts, and to traverse the object, compare each property, compare consumption performance. Dirty checks are triggered after all events in angular that begin with ng-are executed

Page Dynamic Display Time example

Demo_01.html

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Title</title></Head><Body>    <DivNg-app>        <DivNg-controller= "Firstcontroller">            <DivNg-bind= "Date"></Div>        </Div>    </Div>    <Scripttype= "Text/javascript"src=".. /common/angular/angularjs.js "></Script>    <Scripttype= "Text/javascript"src= "Demo_01.js"></Script></Body></HTML>

Demo_01.js

/** * Created by Administrator on 2017/7/21.*/varFirstcontroller =function($scope) {//New One time$scope. Date =NewDate (); //execute once every secondSetInterval (function () {        //dirty Checking by $apply method to dynamically change page data$scope. $apply (function() {$scope. Date=NewDate ();    }); },1000);}

$apply () Description:

$apply () Just into the context of angular, through the $digest () method to trigger the dirty check, when the $digest () method is called, angular executes the angular $eval () method First, if the $eval () parsing failure will throw an exception, Therefore, it is not recommended to call the $digest () method directly, but should use the $apply () method, first let the $eval () method to verify, the data is valid and then execute the following, $apply () if the parameter is not given, will check the $scope all the listening properties, recommended to

$digest () Description:

All $scope and $scope subclasses are dirty checked, and dirty checks trigger the $watch () method, which enables two-way binding of data

$watch () Description:

The ANGULARJS internal Wath enables the page to change depending on the model and is triggered when the $digest () method executes when Watch's value is not the same as the last execution.

Angularjs Getting Started

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.