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区别的详细内容,更多请关注其它相关文章!
推荐阅读
-
包菜和花菜有什么区别,又有什么功效
-
芹菜和水芹的区别在哪?芹菜的作用和功效是什么?
-
Java中HashMap和TreeMap的区别深入理解
-
SQL中distinct 和 row_number() over() 的区别及用法
-
vue的style绑定background-image的方式和其他变量数据的区别详解
-
详解Node.js中path模块的resolve()和join()方法的区别
-
JQ中$(window).load和$(document).ready区别与执行顺序
-
茼蒿的花蕊可以吃吗?它和格桑花有什么区别?
-
孙恩之乱中孙恩和卢循性质有什么区别?孙恩之乱为什么会失败
-
浅谈Java异常的Exception e中的egetMessage()和toString()方法的区别