angularjs-Introductory article

Source: Internet
Author: User

What is Angularjs?

Now that I can find this log, it proves that everyone knows Angularjs and I will not talk about it in a long-winded way.

In fact, Angularjs is a client-side technology written using JavaScript. With Web technologies (HTML, CSS, and JavaScript), making Web application development easier and faster than ever.

Just started to learn, we have to learn the tool, it is recommended to use VS, the version does not care about the following demo, I will basically use vs2013 to develop.

Say so much, together to write a small demo, start our magical journey of Angularjs.
1. Download the package first: Http://files.cnblogs.com/files/xiaowei0705/angular.min.js

2 Create a new page and write the following code:
<!doctype html>

<script src= "Scripts/angular.min.js" ></script>

<body>
Name: <input type= "text" ng-model= "yourname" placeholder= "Please enter name" >

Hello: {{yourname | | ' Little Wei '}}!
</body>

Running results: We did not do any of the page JS processing, incredibly can automatically change!

This example has several important considerations:

    • Text input directives <input ng-model="yourname" /> are bound to a named yourname model variable.
    • The double curly brace tag yourname adds the model variable to the greeting language book.
    • You don't need to register an event listener or add an event handler for the app!

Now try typing your name in the input box, and the name you type will be immediately updated to appear in the greeting. This is the concept of ANGULARJS bidirectional data binding. Any changes to the input box are immediately reflected in the model variable (One Direction), and any changes to the model variable are immediately reflected in the greeting text (the other side).

Analysis of ANGULARJS Application

This section describes the three components of a ANGULARJS application and explains how they map to the model-view-Controller design pattern:

Templates (Templates)

Templates are files that you write in HTML and CSS to show the view of your app. You can add new elements and attribute tags to HTML as instructions for the Angularjs compiler. The ANGULARJS compiler is fully extensible, meaning that by angularjs you can build your own HTML markup in HTML!

Application logic and Behavior (Behavior)

The application logic and behavior are the controllers that you define with JavaScript. Angularjs Unlike standard AJAX applications, you do not need to write listeners or DOM controllers separately because they are already built into the ANGULARJS. These features make your application logic easy to write, test, maintain, and understand.

Model data

Models are derived from the properties of Angularjs scope objects. The data in the model is probably a JavaScript object, an array, or a primitive type, which is not important, and it is important that they belong to the Angularjs scope object.

ANGULARJS maintains a bidirectional synchronization of the data model and the view interface UI through scopes. Once the model state changes, ANGULARJS is immediately refreshed and reflected in the view interface, and vice versa.

In addition, ANGULARJS provides some of the most useful service features:
    1. The underlying services include dependency injection, XHR, caching, URL routing, and browser abstraction services.
    2. You can also extend and add your own specific app services.
    3. These services make it easy for you to write Web apps.
What does the code do?ng-appInstructions:
 lang="en" ng-app>

ng-appThe directive marks the scope of the Angularjs script, and adding the attribute in it means that the ng-app entire angularjs script scope. Developers can also use directives locally ng-app , such as the <div ng-app> Angularjs script to run only in that <div> .

Angularjs Script Tags:
<script src="lib/angular/angular.js"></script>

This line of code loads the Angular.js script, and when the browser loads the entire HTML page, the Angular.js script will be executed, and the Angular.js script will look for ng-app HTML tags that contain instructions after it is run. The tag defines the scope of the Angularjs app.

Expression for double curly braces binding:
<p>Nothing here {{‘yet‘ + ‘!‘}}</p>

This line of code demonstrates the core functionality of the Angularjs template-binding, which consists of double curly braces {{}} and expressions ‘yet‘ + ‘!‘ .

This binding tells Angularjs to need to operate the expression and insert the result into the DOM, and the next step we'll see is that the DOM can be updated in real time as the result of the expression operation changes.

Angularjs expressions angular expression is a JavaScript-like code fragment that Angularjs expressions run only in the scope of ANGULARJS, not throughout the DOM.

Source: Http://files.cnblogs.com/files/xiaowei0705/Web_Demo_001.rar

angularjs-Introductory article

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.