0

I am using ng-repeat in angularjs to display several checkboxes.

<div class="checkbox" ng-repeat="subject in priceinformation.subjects">
   <label>
       <input type="checkbox" ng-model="priceinformation.subscriptioninfo.subject.name"> {{subject.name}}
   </label>
</div>

The problem is all the checkboxes are using the same model, hence if I check one, all are checked. I want to do it in a way that the model can resolve to different values. e.g.

ng-model="priceinformation.subscriptioninfo.subject.{{subject.name}}"

{{subject.name}} should resolve to something like English, History etc, hence a different model for each checkbox. But ng-model="priceinformation.subscriptioninfo.subject.{{subject.name}}" is giving an error.

Note: {{subject.name}} is resolving correctly used elsewhere, and 'priceinformation.subscriptioninfo.subject' is working correctly.

1
  • Please format your question and/or include a jsfiddle Commented May 20, 2015 at 9:01

2 Answers 2

1

Use [] instead of .

ng-model="priceinformation.subscriptioninfo[subject.name]"

Plnkr Demo

Script

$scope.priceinformation ={};

  $scope.priceinformation.subjects = [{"name":"English"},{"name":"History"},{"name":"Maths"}];

  $scope.priceinformation.subscriptioninfo ={};
Sign up to request clarification or add additional context in comments.

Comments

0
<div ng-repeat="item in checks">
    <input type="checkbox" ng-model="item.checked">{{item.name}}
</div>

See Plunkr

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.