I assigned a source variable to two different independent variables, but the second variable changes if I change the first one.
list: Array<any> = [];
savedList: Array<any> = [];
constructor() { }
ngOnInit() {
this.sharedService.list.subscribe(response => {
console.log('Component--List---', response);
if (response) {
this.list= response
this.savedList= response
}
});
}
onEvent(event){
console.log('this.list---1---',this.list,'this.savedList',this.savedList);
this.list.push(event.item.source);
console.log('this.list---2---',this.list,'this.savedList',this.savedList);
}
Printed the console log for clarity:
Component--List--- (1)[{…}]
this.list---before---(1) [{…}] this.savedList (1)[{…}]
this.list---after--- (2) [{…}, {…}] this.savedList (2) [{…}, {…}]