1. ng-repeat
<select> <option value="x.id" ng-repeat="x in list" ng-bind="x.name"> </option> </select>
2. ng-options
<select ng-options="x.id as x.name for x in list" ng-model="listId"> </select>
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!