I Upload array from json file. every 1.5 second I check if there are any changes in file (at the moment I test on one file without any changes), but when I check if
if ( this.itemsParentArray[i] !== this.itemInArray[i] )
it always shows that it's not equal, and console.log (""not equal")
Did I missed something in code??Here it is:
export class HomeComponent {
itemsParentArray = [];
itemInArray = [];
myRes: Content;
showAssigned:boolean = false;
constructor(private structureRequest: StructureRequestService) {
setInterval(() => {
this.timerGetStructure();
}, 1500);
}
// using with setInterval to get new data and sets into content Array with this.updateItems(result) if it's new
timerGetStructure() {
this.structureRequest.sendRequest().subscribe((result) => this.updateItems(result));
}
updateItems(result) {
this.myRes = result;
this.itemInArray = this.myRes.content;
for ( let i = 0; i < this.itemInArray.length; i++) {
if ( this.itemsParentArray[i] !== this.itemInArray[i] ) {
// this.itemsParentArray[i] = this.itemInArray[i];
console.log("not equal");
}
}
}
//
ngOnInit() {
//makes http request and puts result into parentArray after 3 sec.
this.structureRequest.sendRequest().subscribe((result) => this.viewNodes(result));
}
//view items
viewNodes(result) {
setTimeout(() => {
this.myRes = result;
this.itemsParentArray = this.myRes.content;
this.showAssigned = true;
}, 3000);
}
}
As you see it loads data from the same file (I do not change file data!!!):
this.itemsParentArray = this.myRes.content;
and (each 1.5 sec):
this.itemInArray = this.myRes.content;