我试图使用Material Angular自动完成功能,但遇到了displayWith函数,该函数显然可以用作选择时显示的输出。我想在显示功能中调用自定义功能,例如
displayFn(id) {
return this.getValue(id)
}
getValue(id) {
/**return some string
}
Run Code Online (Sandbox Code Playgroud)
对于自动完成
<mat-autocomplete #autoOutlet="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of outletFilterOptions | async [value]="option.outletId">
{{ option.outletName }}
</mat-option>
</mat-autocomplete>
Run Code Online (Sandbox Code Playgroud)
如您所见,我使用id而不是整个对象作为模型。
当显示函数返回未定义this.getValue的错误时,我在Stack Overflow中搜索了一种解决方案,并建议我使用类似的内容[displayWith]="displayFn.bind(this)"。
但不幸的是,这对我也不起作用。我正在使用Angular材质5.1.0。
我有什么想念的吗?
javascript angular-material angular-material2 angular angular-material-5