我只想在选中任何复选框时启用我的表单的确定按钮,但不确定为什么它不起作用。这是我的代码
<form id="myForm" class="form-horizontal" role="form" name="myForm" novalidate>
<li ng-repeat="i in templates">
<input name="myTemplate" ng-model="myTemplate" type="radio" ng-value="{{i.id}}" />
<span>{{i.name}}</span>
</li>
<button ng-disabled="!templates.length || !myTemplate" ng-class="{'disabled' : !templates.length || !myTemplate}" class="btn btn-primary ok-btn">
Submit
</button>
</form>
无论是否检查任何单选按钮
,始终禁用“提交”按钮答案 0 :(得分:2)
您需要使用Object
而不是ng-model
中的值。
JS:
$scope.myTemplate = {};;
$scope.templates = [
{id: 1, name: 'One'},
{id: 2, name: 'Two'},
{id: 3, name: 'Three'}
];
HTML:
<form id="myForm" class="form-horizontal" role="form" name="myForm" novalidate>
<li ng-repeat="i in templates">
<input name="myTemplate" ng-model="myTemplate.value" type="radio" ng-value="{{i.id}}" />
<span>{{i.name}}</span>
</li>
<button ng-disabled="!templates.length || !myTemplate.value" ng-class="{'disabled' : !templates.length || !myTemplate}" class="btn btn-primary ok-btn">
Submit
</button>
</form>