S
S
Seva2016-03-29 12:35:03
JavaScript
Seva, 2016-03-29 12:35:03

How to bind a checkbox to value from an object?

Good afternoon!
There is an object in the controller scope, let's call it interests. It looks something like this:

{
    'sports' : 0,
    'music' : 0
}

The value of all keys is zero.
Then I do the following in the template:
<div class="checkbox" ng-repeat="(key, value) in interests">
    <ion-checkbox autocomplete="off" ng-model="value" value="value">{{ key }}</ion-checkbox>
</div>

It is displayed beautifully, not a single checkbox is checked. The problem is that the binding does not work - when checking checkboxes in the object, nothing happens, and vice versa - if you assign a unit to some key from the console, the checkbox will not be checked.
What am I doing wrong? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-03-29
@Zewkin

ng-model="interests[key]"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question