文章详情页
html - angularjs中用ng-repeat生成几个radio,怎么设置radio的默认选中项?
浏览:233日期:2024-03-14 18:15:59
问题描述
我试了一下ng-model,但是没效果,问题在哪?代码如下:script:
$scope.allMsgType=[{id:'11',name:'输入内容'}, {id:'12',name:'连接h5'}, {id:'13',name:'无详情'}];$scope.msgTypeDefault=$scope.allMsgType[0];
html
<span ng-repeat='x in allMsgType'> <label ng-click='events.getMsgTypeData(x.id)'><input name='msgType' type='radio' ng-model='msgTypeDefault'><span>{{x.name}}</span> </label></span>
问题解答
回答1:可以在数据模型allMsgType上加个属性checked用来标识是否默认选中,然后在input 上增加属性ng-checked 和allMsgType的checked属性绑定,这样就可以通过修改数据对象来操作选中了
标签:
HTML
排行榜
![$fields = $values = [];这条代码一直定义不了,一直报错,老师的源码也是被报错的,执行不了,请问该怎么解决这个问题](http://www.haobala.com/attached/image/news/202205/093622cb60.png)