0
        <li ng-repeat="header in table.headers track by $index">


            <div data-ng-if="header.type === 'checkbox'">
                {{header.value}}<input type="checkbox"
                ng-init="table.addBoxInputs[$index] = {type: 'checkbox', checked: false, value: header.value}"
                />
            </div>

So my program dynamic generate a checkbox, and it passes in a json initially. Now I want that json's checked key to change to true or false, depending on if the checkbox is checked or not.

I don't want to make a method in controller and change it, is there a way to do it in the markup? I tried adding the following:

  ng-model='table.addBoxInputs[$index]'
  ng-change="table.addBoxInputs[$index] = {type: 'checkbox', checked: table.addBoxInputs[$index], value: header.value}"

However this wont work, cause the ng-model will just keep changing the table.addboxinput[$index] to either true or false, base on checkbox

3
  • first off... you have some attribute quote problems in the thing you tried. Commented Jun 22, 2016 at 19:52
  • Could you update your post to include the contents of the 'table' object? Commented Jun 22, 2016 at 19:53
  • @jbrown, the table object contains a lot of stuff, it might just cause confusion. the table.addBoxInput is just an empty array in the beginning. to: kevin B: my bad I made a mistake when I was copying. fixed Commented Jun 22, 2016 at 19:58

1 Answer 1

1

I'm not a proponent of doing this in your markup but if that's how you want to do it then you will need to add the ng-click directive to your check box like this:

<input type="checkbox" ng-init="table.addBoxInputs[$index] = {type: 'checkbox', checked: false, value: header.value}" ng-click="table.addBoxInputs[$index].checked = !table.addBoxInputs[$index].checked" />

Here's a working plunk.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.