Cannot get the data due to "Value below was evaluated just now"

Viewed 17599

Well, I spent a lot of time looking for help for this problem but nothing worked for me. I'm getting an Array of Objects from my provider:

this.encarteProvider.getProdutosEncarte('encarte1').subscribe(prods => {
    this.produtos = prods;
    console.log(this.produtos);
});

In console, it shows:

[]
0: Produto
1: Produto
2: Produto
length: 3
__proto__: Array(0)

If I try this.produtos.forEach(produto => ...), it does not show me nothing, because the Array is empty. I think it's because the data is get asynchronously and (like the Chrome's console says when I ckick in the i icon) "the value was evaluated just now", but why I can show in html using ngFor but can't get the data inside the .ts file ?

2 Answers

I have fixed by reassigning the object again after subscription i.e.

this.prodoctous = this.prodoctous.splice(0,this.prodoctous.length)

Related