The project on angular 1.5

There are groups of identical forms. The first form sets the default settings, the rest for different users. The remaining forms are connected via the ng-model to the dictionary. It is necessary that during the initialization of the form this dictionary does not change.

On user forms, the displayed value should drag from the default if there is no value in the model. When you change the value of a form in default, all the molds must follow it if it does not have its own value. Changing the default should not be saved in user models.

When you change the value on some user, this form ceases to follow the default and begins to follow its model.

Interestingly declarative solution.

If you briefly distribute html

<input type="checkbox" ng-model="default.use_password"/> <table class=table> <tbody ng-repeat="(id,user) in limits"> <tr id="form{{id}}" > <th>{{user._id}}</th> <td><input type="checkbox" ng-model="user.use_password"/></td> <td><a ng-click="user.use_password=undefined">х</a></td> </tr> </table> 

Initial data

 $scope.default = {use_password:true} $scope.limits=[ {_id:1,use_password:true}, {_id:2,use_password:false}, {_id:3}, ] 

In such an example, the display of a check mark in the third user follows the form of default, and the first and second display their status. When you click on the third - it is already set its value.

Tried to do, but the form has ceased to be pressed:

  <input type="checkbox" ng-model="user.use_password" ng-value="user.use_password||default.use_password" /> 
  • If possible, show at least the expected html . From the verbal description is hard to understand what you want. - Stepan Kasyanenko

1 answer 1

Unfortunately, we cannot do without ng-click . Otherwise (using ng-change ), the model does not see the difference between undefined and false , and the code assigning the value to use_password simply does not work.

A working example: https://jsfiddle.net/thesameson/a8Lk3dkv/3/

  • Cool! I'm still new to js and the magic of the triple is equally beyond my control) - eri
  • Updated example. Previously, after removing the use_password parameter when clicking on X, the checkbox did not accept the value from the default object if it was === true . Now everything works as it should. - TheSameSon