AngularJS single-choice and multi-choice boxes implement bidirectional dynamic binding _ AngularJS-js tutorial

Source: Internet
Author: User
This article mainly introduces AngularJS single-choice and multi-choice boxes for Bidirectional dynamic binding. If you need it, refer to the two-way Data Binding mentioned in AngularJS, you will surely think of the ng-model command.

I. ng-model

The ng-model command is used to bind the input, select, textarea, or custom form controls with attributes in their scopes. It binds the values of arithmetic expressions in the current scope to the given elements. If the property does not exist, it is implicitly created and added to the current scope.
Always use ng-model to bind attributes in a data model on the scope, instead of attributes on the scope, which can avoid overwriting attributes in the scope or the scope of future generations!

 

Ii. type = "radio"

You can use the value attribute to specify the corresponding value in the selected state, and use ng-model to map a single volume to the attribute in $ scope. This enables bidirectional dynamic binding when type = "radio.

MaleFemale

Iii. type = "checkbox"

Use the built-in commands ng-true-value and ng-false-value in AngularJS to specify the values of multiple selection boxes in the selected and unselected states, then, the ng-model corresponds to the attribute in $ scope, and the type = "checkbox" bidirectional dynamic binding is realized.

Table TennisFootballBasketball

Iv. Complete example

  
   Radio & checkbox  

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.