AngularJS two-way Data Binding details simple examples, angularjs details

Source: Internet
Author: User

AngularJS two-way Data Binding details simple examples, angularjs details

Angular's two-way data binding, in my personal understanding, is to create a data model through the model, then the data on the view will be stored in the angular program, the data changes on the view will be synchronized to the model, the data changes of the model are also synchronized to the view.

The following demo:

<! DOCTYPE html> 

Running result: after the program is running, Enter text in the input box. The text in the text box will change in sync with the content in the input box. Not surprising! I used to write a large js Code (Listening to the onchange event and assigning the input value to the following strong element). Now I only use one ng-model command. Perferct!

Case Details:

1. The function of the ng-model command: to create a data model, there is a variable username in the model used to store the value of the input element;

2. {username} is an expression. angular automatically calculates the expression and replaces it with the corresponding value.

3. manually input text. The value of the input element changes and is automatically synchronized to the usename variable of the model. {username} is the value of username read from the model, therefore, the content of the strong element changes.

Angular helped us synchronize data.

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related 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.