<mat-form-field>
<input matInput
[formControl]="affiliationName"
[matAutocomplete]="auto">
<mat-label>Affiliation</mat-label>
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let item of items"
[value]="item.value"
(onSelectionChange)="onAffiliationSelect(item)">
<span class="semibold">{{item.code}}</span>
</mat-option>
</mat-autocomplete>
</mat-form-field>
In the code-
affiliationName: FormControl;
ngOnInit() {
this.listenToInput();
}
listenToInput() {
this.affiliationName
.valueChanges.pipe(
debounceTime(300),
distinctUntilChanged(),takeUntil(this.affiliationDestroy))
.subscribe(value => {
//do something
});
}
When the user types in the input field I want to invoke a search in the server side. But after I get my options and the user selects an option and my form control is filled with the chosen option I do not want the valueChanges will be triggered so another search will not be invoked. Is there a way to do it without just adding another formControl or a Boolean variable that will control the server call?
I saw this answer, but it is not my case since I must have an input, so mat-select does not help me. Angular 7 - not triggering "valueChanges" from the template (using mat-option)