Załaduj tablicę z pliku json, co 1,5 sekundy Sprawdzam, czy są jakieś zmiany w pliku (w tej chwili testuję jeden plik bez żadnych zmian), ale kiedy sprawdzić, czyDlaczego dwa równe obiekty wyświetlają "nie równy" w Angular 2
if (this.itemsParentArray[i] !== this.itemInArray[i])
zawsze pokazuje, że nie jest równy, a console.log („” nie równa się ")
czy brakowało mi coś w kodzie ?? Oto ona:
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);
}
}
Jak widać ładuje dane z tego samego pliku (nie zmieniać dane pliku !!!):
this.itemsParentArray = this.myRes.content;
i (każde 1,5 sek):
this.itemInArray = this.myRes.content;
dziękuję. zacznie nad tym pracować. – Serhiy