Cannot create property 'selected' on string 'Information Technology' angularjs

点点圈 提交于 2020-05-02 04:23:12

问题


This is my controller

 $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"];

This is my view where i am binding data

 <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>

Its giving me the error that 'cannot bind property selected to string xyz' Please help!!!


回答1:


subjects is an array of strings, which don't have the property selected that you're trying to bind to your input.




回答2:


for(var j = 0; j < $scope.subjects.length; j++){
    $scope.subjectsArray.push({
        'name':  $scope.subjects[j],
        'value': $scope.subjects[j]
    });   
}

We must provide ng-repeat an object in order to create any property of that object later. We cannot create a property of a string. So I converted my array of string into array of objects.



来源:https://stackoverflow.com/questions/39437597/cannot-create-property-selected-on-string-information-technology-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!