In my AngularJS application, I display contact data in a grid. My typical JSON contacts look like below ...
[ { type: "IM", value: "mavaze123", default: true }, { type: "IM", value: "mvaze2014", default: false }, { type: "IM", value: "mavaze923", default: false }, { type: "IM", value: "mvaze8927", default: false }, { type: "Email", value: "mavaze123@abc.com", default: true }, { type: "Email", value: "mvaze2014@xyz.net", default: false } ]
The last "default" property is actually a switch, the choice of which should change the initial default value of the corresponding contact type above JSON. For each type of contact, there can be one by default, i.e. We can group switches based on the type of contact.
<div ng-repeat="contact in contacts"> <div>{{contact.type}}</div> <div>{{contact.value}}</div> <div><input type="radio" name="{{contact.type}}" ng-model="contact.default" ng-value="true"/></div> </div>
Note. The above code is not accurate, but about the same as it appears inside the custom mesh component.
Now, when I load the page for viewing / editing the form using the above JSON, it correctly shows the radio status of all contacts. The problem occurs after the page loads, when the user selects another contact by default. This actually changes the default model value to true for the newly selected contact, however, the default model value of the original contact remains true even if its radio state changes to uncheck / blur (because they have the same "name" value).
I thought to write a directive, but I can’t start it when I turn on the radio blur / uncheck the box.
There are different messages about binding logical values to switches, but I can’t get them to work in my scenario, since I want to update the model values for a separate switch in the radio group. See That there is no single model representing a radio group.


