I am facing problem in AngularJS 1.6
There are some confusions.
I am iterating an array of objects named aList which contains mutable objects in HTML part.
<div ng-repeat="item in aList>
<a ng-click = "updateDataFun(item)">Click</a>
</div>
Now in controller I have this
constructor(){
this.updateData = {};
}
updateDataFun(item){
// this.updateData = Object.assign({}, item); // this solve the issue.
this.updateData = item;
}
cancelUpdate(){
this.updateData = {}
}
Now, on a modal, I have something like that <input ng-model="updateData.name">
If I change anything (name, an attribute of updateData) via modal and press cancelUpdate() the changes reflect to aList array.
Here are some questions:
- At
updateDataFun(item)method, the assignment is reference assignment (assume). Am I right? So that, if I change onthis.updateDatavia modal, it reflectsitem. Also, changeaListindex value where theitemassociated to. - If so then on
cancelUpdate()invocation,this.updateDatawill be{}. Why does this not reflectitem? It should be{}.
However, if I uncomment this.updateData = Object.assign({}, item); and comment this.updateData = item; then it is working.