在输入标签类型复选框中将 ng-models 与 ng-repeat 绑定时出现问题。我将首先附上我的代码,然后再详细解释。
应用程序/main.html:
<div ng-repeat="feature in features">
<input type="checkbox" ng-model="features[$index].name">{{features[$index].name}}
</div>
<br></br>
<div class="highlighter">
<span ng-class="{emo:Emotions}">Manually</span> <span ng-class="{feel:Feelings}">create</span> the <span ng-class="{emo:Emotions}">entire</span>
</div>
main.js
angular.module('webClientApp')
.controller('MainCtrl', function ($scope,$http) {
[...other variables...]
$scope.features = [{'name':'Emotions'},{'name':'Feelings'}];
[...other parts of code]
});
我们还假设在 main.css 文件中分别引用了类.emo' and
.feel' 以在用户勾选与该功能相关的框时突出显示目标词。
现在,当我一一列出所有输入时,应用程序可以正常工作,如下所示:
<input type="checkbox" ng-model="Emotions">Emotions
<input type="checkbox" ng-model="Feelings">Feelings
但我想将它包装成一个 ng-repeat 并列出控制器范围内的功能,因为我将考虑的功能会更多。当我在框上打勾时尝试上面的代码时,名称更改为“true”。
我已经阅读了很多关于如何将模型绑定到输入标签内的 ng-repeat 的内容,但没有一个解决方案适用于我的案例。有人可以帮帮我吗?