I try to use <mat-autocomplete>
from Angular Material (not AngularJS) without using a reactive form. But all their examples use reactive forms...
What I try to do:
1. when something is typed in the mat-input
, make an Ajax call to retrieve a list of users
2. Display the list of users in the autocomplete (display the user's name), but store the user as the model
3. When the model changes, call a function of my choice
For now I do those crazy things (I say crazy because it seems to much).
<mat-form-field fxLayout>
<input type="text"
matInput fxFlex="100"
[(ngModel)]="listFilterValue"
(keyup)="memberInputChanged(input.value)"
(change)="memberChanged()"
*ngIf="isAutocompleteNeeded()"
#input
[matAutocomplete]="auto">
</mat-form-field>
<mat-autocomplete #auto="matAutocomplete" [displayWith]="getMemberAsStr">
<mat-option *ngFor="let member of members | async" [value]="member">
{{ getMemberAsStr(member) }}
</mat-option>
</mat-autocomplete>
For now, there are only console.log
in my JS to see what's called, with what value so I don't share it here. Am I using the right attributes, the right logic ?
(the members
property in my component is a Rxjs BehaviourSubject)
What I do for now does not work because listFilterValue
is never set to anything.