Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I've been browsing for a few hours, found similar examples, however, couldn't make it to work.

In my JSON file I've got property "accessRight" which could be "full", "read" or "none" Then in HTML I've got 3 checkboxes for "full" "read" and "none". If "accessRight" is set to "read", I want this checkbox to be checked and got this code to do it.

                <input type="checkbox" data-ng-model="accessRight" data-ng-true-value="read"> 

However the checkbox get checked even if "accessRight" isn't set to "read", how could I fix it?

Also tried this but still no luck.

                <input type="checkbox" data-ng-model="accessRight" data-ng-true-value="read"> 
share|improve this question

3 Answers 3

try to use:

checked="accessRight == 'read'"

if your model is accressRight you can also try

data-ng-true-value="accessRight.read == ture"

or

data-ng-true-value="accessRight == 'read'"

it really depend on your model

share|improve this answer

Have you tried

<input type="checkbox" data-ng-model="accessRight" data-ng-true-value="'read'">

Surrrounding read with single quotes, see:

https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D

share|improve this answer

I think you mistake value of data-ng-true-value. The correct like this: https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D

<input type="checkbox" data-ng-model="accessRight" data-ng-true-value="'read'">
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.