I have 1 component named "parent" and another called child (contained in the route) "child", when I go back to the parent component using [routerLink] = "['']" previously loaded variables are not displayed in the component html.
Code in Component Parent:
categories: ProductCategory[];
ngOnInit ()
{
meuServico.getProductCategories().subscribe(
categories
=> {
this.categories = categories;
console.log(this.categories);
...
optional setTimeout (for tests)
...
}
)
}
Parent Component HTML Code:
<div *ngFor="let category of categories"><br>
<a>{{ category.name }}</a>
</div>
Child Component HTML code:
<div class="test-purposes" [routerLink]="['']"</div>;
Important information: when I put this code inside the component in the inscription:
setTimeout (
() => {
log (categories)
}, 1000);
The result of the console.log inside the setTimeout is undefined but the first console.log (outside the setTimeout = real-time) contains the correct result.
Important information: The HTML and also the console log within setTimeout are not appearing after reopening the routerLink in the child component where, it redirects to the parent component
Important information: Before the reopen (first call without any routerLink and subscription) component works perfectly