我正在尝试执行自动填充,但这会引发此错误,请问还有什么更好的方法可以解决?我有这个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;
}