无法创建属性'已选中'关于字符串'信息技术' angularjs

时间:2016-09-11 15:18:18

标签: javascript angularjs angularjs-ng-repeat

  

这是我的控制器

 $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;请帮忙!!!

2 个答案:

答案 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一个对象才能创建任何属性   那个对象以后。我们无法创建字符串的属性。所以我将我的字符串数组转换为对象数组。