javascript - AngularJS ng-models using prototype variables within a repeater -
the best way explain issue example, see here:
javascript
string.prototype.status = {active:false} string.prototype.name = 'testing'; var test = function($scope) { $scope.rows = []; $scope.add = function() { $scope.rows.push(new string('test')); } } html
<div ng-app> <table ng-controller="test"> <tr><td colspan="2"><button type="button" ng-click="add()">add</button></td></tr> <tr ng-repeat="row in rows"> <td>{{row.name}}</td> <td><input type="checkbox" ng-model="row.status.active"/></td> </tr> </table> </div> essentially, bind checkbox row's prototype properties (in case, active).
as can see, if click add button couple of times , attempt tick 1 of entries, all entries ticked. occurs when using ngmodel on property introduced manually prototype.
because prototype's property is shared instances , ng-model 2 way data-binding, when check on 1 entry, property updated , entries updated because they're watching on same property.
Comments
Post a Comment