文章詳情頁
html - angularjs中用ng-repeat生成幾個radio,怎么設置radio的默認選中項?
瀏覽:136日期: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
排行榜
