[英]Display in the Template using @Input Decorator in Angular Material
I have @Input() users
that contains the array of user objects from the parent component. 我有
@Input() users
,其中包含来自父组件的用户对象数组。 It displays the user's name in the normal table. 它在普通表中显示用户名。
<tr *ngFor="let user of users">
<td>{{user.name}}</td>
</tr>
Now I am using Angular Material
and would like to implement the table provided by Angular material. 现在,我正在使用
Angular Material
并希望实现Angular material提供的表格。 For this table, I need the data in the component but I cannot access the data in the child component in ngOnInit
but can access only access on ngOnChanges
. 对于此表,我需要组件中的数据,但无法访问
ngOnInit
组件中的数据,而只能访问ngOnChanges
上的ngOnChanges
。 Since I can only display the data on the template and not able to manipulate the data on the component, it becomes difficult for me to use the Angular Materail table. 由于我只能在模板上显示数据,而不能操纵组件上的数据,因此使用Angular Materail表变得很困难。
Does somebody have any idea how can I deal with this. 有人知道我该如何处理吗? Any help is appreciated.
任何帮助表示赞赏。
Thank you 谢谢
Actually it was quite easy.. Getting the value on ngOnChanges
worked for me. 其实,这很容易。获取
ngOnChanges
的值对我来说很有效。
@Input() users;
dataSource;
ngOnChanges() {
this.dataSource = new MatTableDataSource<any>(this.users);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.