【发布时间】:2020-01-31 22:57:10
【问题描述】:
我尝试使用 Material Angular 自动完成功能,但遇到了 displayWith 函数,该函数显然可以用作选择时显示的输出。我想在显示函数中调用一个自定义函数,比如
displayFn(id) {
return this.getValue(id)
}
getValue(id) {
/**return some string
}
用于自动完成
<mat-autocomplete #autoOutlet="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of outletFilterOptions | async [value]="option.outletId">
{{ option.outletName }}
</mat-option>
</mat-autocomplete>
如您所见,我使用id 作为模型而不是整个对象。
当显示函数返回 this.getValue 未定义的错误时,我在 Stack Overflow 上搜索了解决方案,并建议我使用类似 [displayWith]="displayFn.bind(this)" 的内容。
但不幸的是,这对我也不起作用。我正在使用 Angular 材料 5.1.0。
我有什么遗漏吗?
【问题讨论】:
标签: javascript angular angular-material angular-material2 angular-material-5