我正在尝试进行自动完成,但这会引发此错误,有什么更好的处理方法?我有这个来自我的数据库的 json
[{
'ID': '1',
'Initials': 'AC',
'Name': 'Acre'
},
{
'ID': '2',
'Initials': 'AL',
'Name': 'Alagoas'
},
{
'ID': '3',
'Initials': 'AM',
'Name': 'Amazonas'
}
]
这个组件 HTML
<mat-form-field class="mr-24" fxFlex="33">
<input matInput placeholder="Estado" formControlName="State" [matAutocomplete]="autoState" required>
<mat-autocomplete autoActiveFirstOption #autoState="matAutocomplete" [displayWith]="getOptionText" >
<mat-option *ngFor="let state of filteredStateOptions | async" [value]="state.Name">
{{state.Name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
这是我从角度站点获取的方法
onStateChanges(): void {
this.filteredStateOptions = this.clientForm.get('State').valueChanges.pipe(startWith(''), map(value => this.filterStateOptions(value)));
}
filterStateOptions(value): any {
const filterValue = value.toLowerCase();
const filteredState = this.states.filter(option => option.Name.toLowerCase().indexOf(filterValue) === 0);
return filteredState;
}