Home > Web Front-end > JS Tutorial > body text

The difference between ng-repeat and ng-options

怪我咯
Release: 2017-06-27 11:48:15
Original
1581 people have browsed it

1. ng-repeat

<select>
<option value="x.id" ng-repeat="x in list" ng-bind="x.name">
</option>
</select>
Copy after login

2. ng-options

<select ng-options="x.id as x.name for x in list" ng-model="listId">
</select>
Copy after login


3. Difference:
As shown above, when selecting When ng-repeat needs to be written in the option, ng-options does not require an option and will be automatically generated.
ng-options must be matched with ng-model. ng-model obtains the value of the list.
Notice! !
1) The value type of .ng-options is number. When list.id is of type string, it cannot be looped.
2) The value type of .ng-repeat is string. When list.id is of type number Unable to loop
You can choose different ID types. This is a problem found in recent projects and can be solved by the above method

The above is the detailed content of The difference between ng-repeat and ng-options. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!