javascript - AngularJS ng-models using prototype variables within a repeater -


the best way explain issue example, see here:

http://jsfiddle.net/ywvdk/

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

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -