I am using Angular autocomplete which I have connected to an API. Search results should not be returned until after typing has started. After typing a few letters in the box this error comes up in the console.
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'xxxx'. Current value: 'undefined'..
I have tried using change detection but that hasn't helped.
The main issue seems to be with the collectFieldValue function because, without it, when I console log the value, the value never becomes undefined.
Search.component.html
<input type="text" class="searchItem" placeholder="Begin your’"
aria-label="Begin your search" matInput [matAutocomplete]="auto" (ngModelChange)="inputCheck($event)"
[(ngModel)]="searchInput" (focusout)="onFocusOut()" (focus)="onFocus()"
(keydown)="onKeyDown()" >
Search.component.ts
@Input() setSelectedLocation!: Function;
inputCheck(value: any) {
if (value !== undefined && value !== "" && value !== null)
{
this.collectFieldValue(value, this.sharedService.sharedVal && this.sharedService.sharedVal !== "" ? this.sharedService.sharedVal : undefined)
}
}
Main.component.html
<app-search-box
[collectFieldValue]="triggerLocationSearch"
[setSelectedLocation]="setSelectedLocation">
</app-search-box>