How to set a checkbox selected based on model value

I have a flag, and the value of this flag is fixed as "A". I want the flag to be selected if the model value matches the attribute of the value of the flag.

<div class="form-horizontal">
    <label class="col-md-2">
        <input type="checkbox" id="Animals" name="Animals" ng-model="ModelData.Animals" value="A" /> Animal(s)
    </label>
</div>

But using the code above, selecting a checkbox does not work automatically. How can I achieve this?

+3
source share
2 answers

Please try using: ng-checked="ModelData.Animals == 'A'"

Additional information on ng-checked: http://docs.angularjs.org/api/ng.directive:ngChecked

+3
source

You need to use the directive ng-checkedto test it with an expression.

Here is a working example: fiddle

0
source

All Articles