您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ng-repeat和ng-options区别

2024/2/21 4:21:51发布32次查看
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区别的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product