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

share|improve this question
    
plnkr.co/edit/cdwY1EzKRAL0qlwC9eyO?p=preview .Its working for me ,its look like different reason – RIYAJ KHAN Sep 11 '16 at 15:25
    
Its binding the data for me too, but in my $scope.$watch function when i try to get the property value.selected, then it shows me 'cannot create property on string' error in console.. – Abdul Moiz Sep 11 '16 at 15:34
    
Please add watch scripta – RIYAJ KHAN Sep 11 '16 at 15:37
up vote 1 down vote accepted

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

share|improve this answer
    
So what should i do with subject to make it have property selected? – Abdul Moiz Sep 11 '16 at 15:36
    
You could either just add a property to $scope like selectedValue or you could turn subjects into objects, i.e. subjects = [{ value: "Computer Science", selected: false }, ... – spongessuck Sep 11 '16 at 15:39
    
Thanks did the second one. – Abdul Moiz Sep 11 '16 at 17:37
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.