1

I am using chrome.

This is my html code

ng-repeat="tag in formData.amenities"><label><input type="checkbox"  ng-model="tag.enabled">{{tag.text}}:{{tag.enabled}}

I am able to collect tag values when I check/uncheck from the view. The problem is in reverse binding.

I am reading the values back and then applying to the above code. I can see that tag.enabled is set to true but the view doesnt show checked.

I have tried $scope.apply but even that doesnt update the view.

2

1 Answer 1

1

DEMO

Use ng-checked directive

<body ng-controller="MainController">

  <div ng-repeat="tag in formData.amenities">
    <label>Checkbox: <input type="checkbox" ng-checked="tag.enabled" ng-model="tag.enabled">{{tag.text}}:{{tag.enabled}}
    </label>
    </div>

</body>

In Controller:

angular.module("app", [])
    .controller("MainController", function ($scope) {
    $scope.formData = {
        amenities: [{
            "text": "First",
             "enabled": true
        }, {
            "text": "second",
            "enabled": false
        }, {
            "text": "Thid",
            "enabled": true
        }]
    };
});
Sign up to request clarification or add additional context in comments.

2 Comments

Doesnt work. If I add ng-checked everything becomes checked even if it enabled is false.
Please check demo, you will get the point. Also structure your object accordingly

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.