Angularjs Development Guide 12:angularjs templates, CSS, data binding detailed

Source: Internet
Author: User

Template

The Angularjs template is a declarative rule. It contains information about the model and the controller and is then rendered as a view that the user sees in the browser. It is a static DOM that contains the elements and attributes specified by Html,css and Angularjs. Angularjs elements and attributes let angular add behavior to the template Dom, or deform, to become a dynamically dom.

Here are the ANGULARJS elements and attributes you can get in the template:

    • Directives-a property or element that expands existing DOM elements or displays reusable DOM components. It can also be called a widget.
    • Blending (Markup)-a double curly brace is a angular built-in blend that binds an expression to an element.
    • Filter-Format the output to the user's data.
    • Form Control-Allows you to verify user input

Note: In addition to declaring elements in a template, you can also get these elements in your code.

The following example shows a simple template. It contains standard HTML tags, angularjs directives, and expressions that are bound with double curly braces.

 with ngcontroller directive--  <body ng-controller= "Mycontroller" >   <input ng-model= " Foo "value=" bar ">    with ng-          click Directive, and' ButtonText '          in" {{}} "markup   --<button ng-click=" Changefoo () ">{{buttonText}}</button>   <script src=" Angular.js "> </body>

In a simple single-page application, the template consists of the html,css and the ANGULARJS instructions contained in an HTML page (usually index.html). In more complex applications, you can display multiple views in a page with a local template, which is a template fragment defined in a separate HTML file. You import these local templates in the main page by using the $route service together with the Ngview directive.

Css

Angularjs sets the following CSS class names, which you can easily use to add styles to your app.

    • Ng-invalid, Ng-valid

      • When an input value in an element does not pass validation, Angularjs adds the class name ng-invalid to the element.
    • Ng-pristine, Ng-dirty

      • The input directive adds the Ng-pristine class name to the input element in the new directive (no user interaction), and the interaction is changed to ng-dirty .
Data binding

Data binding in Angularjs is the automatic synchronization between the model and the view. This implementation allows you to concentrate on your model. The view is always the projection of the model, and when the model changes, the view reflects that change, and vice versa.

How most template systems are bound. They combine models and templates to generate views that are not dynamically updated by the combined process. To make things worse, the interaction between the user and the view is not reflected in the model. This means that the developer will automatically write the view and the model bidirectional synchronization code.

The Angularjs template works differently. The difference is that:

First, the template (non-compiled HTML with tags such as custom attributes attached) is compiled by the browser;

Second, the final result of compilation is a dynamic view. The dynamic here refers to any changes in the view that are directly reflected in the model, and vice versa. This allows the model to always apply the unique identity of the state, which greatly simplifies the programmer's work. You can simply assume that the view is a projection of the model.

Because the view is just a projection of the model, the controller is completely detached from the view, and the view is transparent to it. This makes testing easier because you don't need to be concerned about DOM or browser changes.

Come on!

Angularjs Development Guide 12:angularjs templates, CSS, data binding detailed

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.