This is the form that I am using:
<form [formGroup]="searchForm" id="searchForm">
<mat-form-field>
<input
matInput
type="text"
name="awesome"
id="awesome"
[formControl] = "formCtrl"
[matAutocomplete] = "auto"
value="{{ awesomeText }}"
[matAutocomplete]="auto">
<mat-autocomplete #auto = "matAutocomplete">
<mat-option *ngFor = "let res of result | async" [value] = "res">
{{res}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
And this is inside constructor()
:
this.formCtrl = new FormControl();
this.formCtrl.valueChanges.subscribe((newValue) => {
this.result = this.find(newValue);
console.log('yes');
});
The yes
is printing so I know that this is working but mat-autocomplete
does not show anything. The result
variable is also updating as I can see it printing on console. I am not able to understand why the searched values are not being displayed.
I would appreciate any help!
Edit
This is the find()
method:
find(val: string): string[] {
const matchFound = [];
for (let i = 0; i < dataJson.length; i++) {
if (dataJson[i].text.toLowerCase().startsWith(val) || dataJson[i].text.startsWith(val)) {
matchFound.push(dataJson[i].text);
}
}
console.log('matches ' + matchFound);
return matchFound;
}