<div class="prod-div results" *ngIf="product.name.indexOf(searchProd$ | async |lowercase) !== -1
|| product.details.indexOf(searchProd$ | async |lowercase) !== -1">
And I want to show this
{{ searchCount() }} search results for "{{ searchProd$ | async }}"
I used this code:
searchCount() {
let num = document.getElementsByClassName('results');
console.log (num.length);
return num.length;
}
The problem is it does not dynamically update, lets say the results should be 6 for 'a', it shows 0 and only updates to 6 if I click the screen or type another key.
EDIT: I get this error core.js:6486 ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '0'. Current value: '6'
You can simply create a trigger in component.ts
ngAfterViewInit(){
searchCount();
}
or you can use any other life cycle hook.