Invite组件中的displayUser函数接收不到参数,参数始终是undefine
来源:2-11 Autocomplete 的使用

穿鞋的面条
2017-12-19
HTML:
<md-autocomplete #autoMembers="mdAutocomplete" [displayWith]="displayUser">
<md-option *ngFor="let item of items">
{{item.name}}
</md-option>
</md-autocomplete>
TS:
export class InviteComponent implements OnInit {
items = [
{id:1, name:'张三'},
{id:2, name:'李四'},
{id:3, name:'王五'}
]
constructor() { }
ngOnInit() {
}
displayUser(user: {id:string, name:string}) {
console.log(user);
return user ? user.name : '';
}
}
写回答
2回答
-
505380967
2018-07-13
<form> <h2 mat-dialog-title>邀请组员</h2> <div mat-dialog-content> <mat-form-field class="full-width"> <input matInput type="text" placeholder="组员姓名" [matAutocomplete]="autoMembers"> </mat-form-field> <mat-form-field class="full-width"> <input matInput type="text" placeholder="project desc"> </mat-form-field> </div> <div mat-dialog-actions> <button type="button" mat-raised-button color="primary" (click)="onClick()">保存</button> <button type="button" mat-button mat-dialog-close>关闭</button> </div> </form> <mat-autocomplete #autoMembers="matAutocomplete" [displayWith]="displayUser"> <mat-option *ngFor="let item of items"> {{item.name}} </mat-option> </mat-autocomplete> displayUser(user: {id: string, name: string}){ return user ? user.name : ''; }
获取不到值。。。使用[displayWith],后面给个函数的引用,执行的时候相当于 displayUser(item)吗?
012020-11-20 -
接灰的电子产品
2017-12-19
这代码贴的不全啊,input没有啊
012018-07-13
Angular打造企业级协作平台,让你在Angular领域中出类拔萃
全网首个介绍官方 Material 组件库用法与 Redux 在 Angular 中的应用
998 学习 · 536 问题
相似问题