这是我的控制器
$scope.subjects = ["Computer Security", "Graphics and Multimedia", "Networks", "Computer Science and Engineering", "Game Design", "Programming", "Information Technology", "Software Engineering", "Technology Management", "Telecommunications", "Web Development", "Sociology", "Psychology", "General", "Social Work", "Criminal Justice", "Law and Paralegal", "Public Safety", "Forensic Sciences", "Counseling", "Homeland Security", "Political Science", "Public Administration"];
这是我的视图,我在哪里绑定数据
<label class="concentration-label3" ng-repeat="value in subjects">
<input ng-model="value.selected" ng-disabled="subjectCheckedCount == subjectLimit && !value.selected" type="checkbox" name="concentrations" class="concentration-label3__input js-concentration-value" value="{{value}}" data-mixpanel-subject="Design" >
<span class="concentration-label3__title" for="conc1">
{{value}}
<span class="concentration-label3__title__checkmark4"></span>
</span>
</label>
它给我的错误是“不能将选中的属性绑定到字符串” XYZ&#39;请帮忙!!!
答案 0 :(得分:1)
subjects
是一个字符串数组,它没有您尝试绑定到输入的属性selected
。
答案 1 :(得分:0)
for(var j = 0; j < $scope.subjects.length; j++){
$scope.subjectsArray.push({
'name': $scope.subjects[j],
'value': $scope.subjects[j]
});
}
我们必须提供ng-repeat一个对象才能创建任何属性 那个对象以后。我们无法创建字符串的属性。所以我将我的字符串数组转换为对象数组。