javascript - Changing ng-model value when using ng-repeat and $index -
i have set of divs, inside ng-repeat. when use ng-model these, updating when change value of model function in controller. i.e., if change model, divs reflecting same value.
html:
<tbody ng-repeat="aw in aws"> <div ng-model="currentvalue" ng-init="initializeselects(aw.id)">{{currentvalue}}</div>
controller code:
$scope.initializeselects = function(awid) { $scope.currentvalue = "read"; }
i tried changing code to:
<tbody ng-repeat="(i, aw) in aws track $index"> <div ng-model="currentvalue[i]" ng-init="initializeselects(aw.id, i)">{{currentvalue[i]}}</div>
and
$scope.initializeselects = function(awid, i) { $scope.currentvalue[i] = "read"; }
in case, currentvalue undefined , model value can not changed. why undefined?
any inputs helpful, in advance!
Comments
Post a Comment