How do get rid of the mentioned error when *ngIf
directive is based on an asynchronous condition?
In my main component (products.ts
) I am subscribed to an observable, that is a result of a user's selection, which he can make through interacting with many components (including products.ts
). In the template of this component (products.html
) I need to check if any products are selected and if so, display their number.
It all works perfectly, but I'd like to get rid of the error.
Product.ts
ngOnInit() {
this.productService.getProducts().subscribe(data => {
this.products = data;
this.countProducts = this.products.length;
});
}
Product.html
<span *ngIf="countProducts" [matBadge]="countProducts"></span> //if countProduct is not 0 or undefined, display the number of products