Angularjs Simple Basics of learning notes

Source: Internet
Author: User

Angularjs is a Google project that makes up for HML's lack of construction and extends HTML tags through directives (directive), allowing developers to use HTML to declare dynamic content.

Angularjs is mainly used to develop a single page application (SPA)-based project.

Angularjs four main features: 1.MVC mode 2. Bidirectional data binding 3. Modular 4. Instruction System

in order to use angular, all applications must do two things first1.Download load angular.js library2.Use the Ng-app directive to tell angular which parts of the DOM should be managed。 Some common directives in angular: Ng-app: root element in Web page, Ng-init: Initialize data; Ng-bind: Bind data; Ng-show: Show; Ng-hide: Hide Data ; Ng-class: Control Classng-click: Bind fixed-point event; ng-disabled: Disable event; Ng-model: Bind data in HTML; ng-repeat: cyclic data;

1. Angularjs MVC

Model : Data Model layer

View : views layer, responsible for showing

Controller: business logic and control logic

Advantages: Code Modular Code logic is clear, high-value-shifting, late maintenance, code reuse, code size is getting bigger, the role of segmentation is the trend

Cons: run a little less efficiently

$scope control scope; $rootscope: root scope, global scope;

1. Angularjs The $apply method inside the $scope $apply Method: Scope provides a $apply method for propagating model changes $apply Method Usage Scenarios:$apply must be called after ANGULARJS external controllers (DOM events, external callback functions such as jquery UI space, etc.) have called the ANGULARJS function. In this case, you need to command Angularjs to refresh itself (model, view, etc.), $apply is used to do this thing. $apply Method Considerations:As long as you can, pass the code and functions you want to execute to $apply, instead of executing those functions and then calling $apply. For example, you should execute your code as follows: $scope. $apply (function () {$scope. variable1 = ' some value '; Executesomeaction ();}); 2. Angularjs The $watch method inside the $scope $watch method: The $watch method monitors the model changes.

Angularjs Simple Basics of learning notes

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.