i have function gets object json, , list key-value pairs in ng-repeat. form value true/false , depending on that, checked or not.
<form class="form-horizontal"> <div class="form-group form-group__bordered" ng-repeat="(key, value) in listofnotificationtypes"> <label for="inputemail3">{{ key | trimkey }}</label> <div class="checkbox-wrapper"> <input type="checkbox" class="checkbox" ng-checked="{{value}}"> </div> </div> <div class="form-group"> <div class="col-12 clearfix"> <a href="#" class="btn" ng-click="updatenotificationsettings()"> save </a> </div> </div> </form>
it works well, want pick changed key-value pairs , send them via function when hit save button.
how can bind input in ng-model have correct json format passed, like
{ "key1":"value1", "key2":"value2", "key3":"value3", ... }
i suppose should use ng-model capture data, not know how handle it.
so, type of of object have use input this.
<input type="checkbox" class="checkbox" ng-model="listofnotificationtypes[key]">
here plunker demonstrating implementation.
notes: 1 few note in future may need transform object in list of objects this
[ {key: "key1", value: false}, {key: "key2", value: true}, {key: "key3", value: false} ];
for case code on front end
<div class="form-group form-group__bordered" ng-repeat="notification in listofnotificationtypes"> <label for="inputemail3">{{ notification.key }}</label> <div class="checkbox-wrapper"> <input type="checkbox" class="checkbox" ng-model="notification.value"> </div> </div>
Comments
Post a Comment