AngularJS:将单选按钮绑定到ng-model,在ng-repeat中带有角度
AngularJS : binding radio buttons to ng-model with angular in ng-repeat
我目前正在学习角度.js遇到了一个问题。我根据从数据库中获取的项目列出单选按钮,当我单击其中任何一个时,我的模型都不会更新。我添加了一个输入进行测试,输入立即更新了模型。
知道我错过了什么吗?
更新:问题似乎来自引导和包装单选按钮的跨度。如果我删除跨度,模型会更新
<div ng-repeat="question in questionnaire">
<div class="btn-group col-xs-offset-1 col-xs-2 col-sm-2" data-toggle="buttons">
<span class="btn btn-primary">
<input type="radio" name="question{{$index}}" ng-model="formData[$index]" ng-value="false"> No
</span>
<span class="btn btn-primary">
<input type="radio" name="question{{$index}}" ng-model="formData[$index]" ng-value="true"> Yes
</span>
<input type="text" name="testEntry{{$index}}" ng-model="formData[$index]" />
</div>
{{formData}}
<span ng-bind="question.QuestionPhrase" class="message col-xs-8 col-sm-8"></span>
</div>
所以事实证明,问题来自跨度。我将它们更改为标签,它起作用了。
这是代码:
<div ng-repeat="question in questionnaire">
<div class="btn-group col-xs-offset-1 col-xs-2 col-sm-2" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="question{{$index}}" ng-model="formData[$index]" value="false"> No
</label>
<label class="btn btn-primary">
<input type="radio" name="question{{$index}}" ng-model="formData[$index]" value="true"> Yes
</label>
</div>
{{formData}}
<span ng-bind="question.QuestionPhrase" class="message col-xs-8 col-sm-8"></span>
<br /><br /><br />
</div>
相关文章:
- Ng点击记住单选按钮选择
- 将 ng 重复中的单选按钮设置为选中
- 如何在控制器内获取ng重复单选按钮值
- AngularJS-使用ng repeat构建的单选按钮的设置值
- 如何在AngularJS(ng-repeat)中获取选定的单选按钮数据
- UI 引导单选按钮在 ng-repeat
- AngularJS ng-repeat,两个单选按钮无法正常工作
- 获取 Angular JS 中单选按钮中选中的单选按钮的值,该值为 ng-repeat
- 将用户选择的多个单选按钮选项存储在使用 ng-repeat(s)构建的角度 js 中
- 如何使复选框表现得像ng repeat中的单选按钮
- 使用具有多个重复ng的单选按钮组的ng-model
- 如何在ng-repeat范围之外获取单选按钮的值
- 对于第一次使用ng-repeat而不是第二次使用ng-repeat创建的单选按钮,调用Ng-change事件
- Angular UI.Bootstrap'的单选按钮在ng-repeat中表现得很奇怪
- Angular中,ng-repeat可以创建多组单选按钮
- 在Angularjs中将Select ng-options转换为单选按钮ng-repeat
- AngularJS的ng-repeat单选按钮默认情况下是不被选中的
- 不能在Angular.js中使用ng-repeat设置默认选中的单选按钮选项
- AngularJS:将单选按钮绑定到ng-model,在ng-repeat中带有角度
- 使用NG-repeat创建一个包含多个单选按钮的表单:希望重置所有单选按钮的值