angular.js - angularjs如何默认选中radio

浏览:35日期:2023-01-27

问题描述

<label class='radio-inline'><input name='display' type='radio' value='true' ng-model='institution.display' checked required>显示</label><label class='radio-inline'><input name='display' type='radio' value='false' ng-model='institution.display'>隐藏</label>

angularjs如何默认选中第一个

问题解答

回答1:

使用 ng-checked 即可。

<label class='radio-inline'> <input name='display' type='radio' value='true' ng-model='institution.display' ng-checked='true' required> 显示</label><label class='radio-inline'> <input name='display' type='radio' value='false' ng-model='institution.display'> 隐藏</label>回答2:

institution.display 的值设成对应的

回答3:

checked = 'checked'

回答4:

ng-checked

同时加上ng-model绑定元素就可以了

回答5:

双向绑定双向绑定双向绑定重要的说三遍~~~

$scope.institution.display = 'true';

即ng-model和value相同即可。

回答6:

可在 ng-repeat 中使用 ng-checked , 形如:

<label ng-repeat='(key, val) in genders track by $index'> <input type='radio' name='gender' value='{{key}}' ng-checked='list.gender==key'>{{val}}</label>

相关文章: