But in my code I can not traverse the Array and in the console it gives different values.
The first console shows all visitors.
But in the second it gives zero lenght.
And do not even enter my forEach.
I woud say the function _userService.getVisitantesPorArray() woud take same time to execute.
But js wont wait and executes the other lines before the result comes back from the function.
I’m not talking about the argument in the provider, but rather the array in the component. You say
That implies to me that until that button is clicked, the visitantes property in the component that you are trying to iterate across with forEach is undefined. That will throw an error during rendering that will mysteriously break virtually everything in your page. Always initialize all component properties referred to in templates.
I do not think I understand.
This array is within the method and is temporary.
It is being started in the method, filled with getVisitant and returned at the end.
…but what I think you mean is a controller property, aka:
export class Page {
visitantes: Array<User>;
...
}
That’s the only way you could be using it in the associated template with forEach. “Temporary” or lexically-scoped variables are invisible to templates.
This is the visitantes that I’m suggesting initializing:
export class Page {
visitantes: User[] = [];
...
}
Tb did this and did not solve.
That’s strange. In a line of code it renders the values and soon in the next line the same variable renders another without no other action.
You can’t pretend that asynchronous things are synchronous. getVisitantesPorArray cannot return Array<User>. I was under the impression that forEach was Array.forEach.
Now the entire discussion is radically different, and I don’t speak enough Portuguese to know what getVisitantesPorArray needs to be called, but it probably shouldn’t be that. See this post for some background.
Thanks for the personal help.
I found a library called RxFire.
I used the combinedLatest design with it, and I was able to do the merge of objects.
So, I no longer have to generate an Array.