javascript - How can I prevent scope variable from changing whenever the model value changes in Angular JS -
here controller function in typescript:
let temp = null; temp = _.find(this.scope.model.maintenancearray, function(_data,_key) { return _data.id === currentid; } this.scope.originaldata = temp; this.scope.maintenancedata = temp; and in view,
<input type="text" class="form-control" name="datefrom" placeholder="{{datedefault}}" ng-model="maintenancedata.from" required /> basically used maintenancedata ngmodel , want keep originaldata is. problem originaldata changed every time model changes. how can prevent originaldata updating?
this happens because variable temp passed reference both originaldata , maintenancedata, both of variables reference same object. avoid can create copy of temp object 1 of 2 variables. this:
this.scope.originaldata = angular.copy(temp); this.scope.maintenancedata = temp; there several other ways copy objects out there, 1 example.
Comments
Post a Comment