0

I have an array of objects which I am databinding -

$scope.records = [
    {field: "Full Name", value: "Joe Hanigan", isVisible: true},
    {field: "Age", value: "52 Years", isVisible: true},
    {field: "Diagnosis", value: "Common Cold", isVisible: true},
    {field: "Hospital Elum", value: "Alpha Lopus Epsum", isVisible: false},
    {field: "Hospital Code", value: "CKD34-23", isVisible: false}
  ];

I am just displaying 'field' and 'isVisible' as a check box. I want to toggle the value of 'isVisisble' when a user checks/unchecks, the box in the browser.

How do I do that?

1 Answer 1

3

I assume you use your array in a ng-repeat, where you will define an input field of type checkbox. You use ng-model to bind the field to the model:

<div ng-repeat="record in records">
   <input type="checkbox" name="isVisible" ng-model="record.isVisible">
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the answer. However I would like to run some logic when the change is made, maybe make some server side changes, do some validations, how do I do that? In this case I would like to update it on the server. And the model will be retrieved from an angular service.

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.