I've managed to connect my QueryList object to an observable with this line of code:
this.data.currentArray.subscribe(array => this.array = array);
But when I was trying to iterate through it, for some reason I didn't get the up-to-date values. More specifically I've used console.log
to check the values, and:
When I wrote
console.log(this.array.toArray());
- I got the up-to-date value on the 0th index;But when I wrote
console.log(this.array.toArray()[0]);
- I didn't.
Someone suggested that it's because toArray()
creates a new object, and thus disconnects from the observable. But if that's the case, how come the console.log(this.array.toArray());
line got me the up-to-date value?
I tried the answers from QueryList changes subscribe does not work and How can I get children elements from QueryList in Angular 2?, but neither of them worked.