but with that i also wanted to display original values which obviously shoudn't change.
Use angular.copy(/* array */)
. It will create new copy (instance) of old array.
BTW a
collection must be defined as $scope.a
Demo Fiddle
Question
i have a collection of values whose structure lets assume to be
var a = [{id:1, value:12, name="one"}, {id:2, value:34, name="two"},...]
i wanted to display this in a series of controls so that user can change the values. but with that i also wanted to display original values which obviously shoudn't change.
i found out a way that is working and my code is something like this using ng-init
<div ng-repeat="p in a">
<div class="control-group" ng-if="p.value>0">
<label class="control-label" ng-bind="p.name"></label>
<div class="controls controls-row" ng-init="v=p.value">
<input class="span1" value="{{v}}"/>
<input type="number" ng-model="p.value" class="span2" />
</div>
</div>
</div>
being a complete newbie in angularjs i dont know what implications this might have as i have very little experience in thinking about $watch and performance.
Is it ok to do so?
Solution
but with that i also wanted to display original values which obviously shoudn't change.
Use angular.copy(/* array */)
. It will create new copy (instance) of old array.
BTW a
collection must be defined as $scope.a
Demo Fiddle