The road of ANGULARJS self-study--Initial knowledge angularjs and data binding

Source: Internet
Author: User

What is AngularJS?

Angularjs's official documentation describes it this way. A client-side technology written entirely using JavaScript. Working with other historic web technologies (HTML, CSS, and JavaScript) makes Web application development easier and faster than ever.
Angularjs is primarily used to build single-page Web applications. It makes building interactive, modern web applications easier by increasing the level of abstraction between developers and common Web application development tasks.
ANGULARJS's development team described it as a structured framework for building dynamic Web applications.
Angularjs makes it easy to develop Web applications and reduces the difficulty of building complex applications. It provides a range of advanced features that developers often use in modern web applications, such as:

    • Decoupling application logic, data models, and views
    • Ajax Services
    • Dependency Injection
    • Browsing history (make bookmarks and forward, back buttons work as you would in a normal web app)
    • Test
    • More versatility
Angularjs is open source.

I recently played GitHub and saw some of the projects license is MIT, and I thought MIT, a colleague of mine, knew that MIT meant you could contribute code to ANGULARJS and make it better. More content on the contribution code can be found in the "Contribution Code" section of Angularjs's website. Do not know Angularjs official website, can Baidu (I never remember the official website, are Baidu).

The first ANGULARJS program--hello World
<! DOCTYPE html><html ng-app><head>    <title>Simple app</title>    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/ Angular.js ">    </script></head><body>    <input ng-model="name" type="text" placeholder=" Your name ">    <H1>Hello{{ name }} </H1></body></html> 

While this example is not interesting, it shows one of the most basic and impressive features of ANGULARJS: Data binding.
The ANGULARJS uses a completely different solution. It creates a live template instead of a view, instead of updating the DOM after merging the data into the template. The values in any of the standalone view components are dynamically replaced. This feature is one of the most important features in Angularjs, and it's the key to writing Hello world with just 10 lines of code and without any javascirpt.
To do this, simply reference angular.js in an HTML page and explicitly set the Ng-app property on a DOM element. The Ng-app property declares that all the content it contains belongs to this Angularjs app, which is why we can nest Angularjs apps in a web App. Only elements that are contained by DOM elements with the Ng-app attribute are affected by ANGULARJS.
Automatic data binding allows us to interpret the view as a mapping of model state. When the client's data model changes, the view reflects these changes and does not require any custom code to be written, and it works.
In the World of MVC (Model View controller, models, views, controllers), controllers don't have to worry about the work of rendering views. This way we don't have to worry about separating the view and controller logic, and it can make testing both simple and enjoyable.

Best Practices for data binding

Because of the characteristics of JavaScript itself, and its different ways of handling values and references, it is generally considered a best practice in angular to make reference bindings in a view through the object's properties rather than the object itself.

<!doctype html><html ng-app><head>    <script src="Https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js" ></script></head><body>    <div ng-controller="Mycontroller">        <H1>Hello{{ clock.now }}! </H1> </div> <script type="text/javascript" src="Js/app.js">  </script></body></HTML >         

In this example, updating the value of Clock.now is a better choice than updating $scope.clock every second.

//in app.js  function  mycontroller   ( $scope )  {  $scope . Clock = {now: new  Date ()}; var  updateclock =  function   ()  {  $scope . Clock.now = new  Date ()}; SetInterval (function   ()  {  $scope .  $apply  (Updateclock); }, 1000 ); Updateclock ();}; 

Angularjs Self-learning path--angularjs and data binding

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.