欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

ng-repeat和ng-options区别

程序员文章站 2022-03-19 18:03:57
...
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、区别:
如上所示,当在select中时ng-repeat需要写在option中,而ng-options不需要option,会自动生成。
ng-options 一定要和ng-model 搭配,ng-model获取的是列表的value值。
注意!!
1).ng-options的value值得类型是number,当list.id是string类型时无法循环
2).ng-repeat的value值类型是string,当list.id是number类型时无法循环
可以根据id类型不同选择,这是在最近的项目中发现的问题,通过上述方法解决

以上就是ng-repeat和ng-options区别的详细内容,更多请关注其它相关文章!