I have mat-paginator in a child component a shown below:
child.component.html
<mat-paginator #paginator></mat-paginator>
I want to get this paginator from parent component using @ViewChild() as shown below:
parent.component.html
<child
<!-- code omitted for simplicity -->
>
</child>
***parent.component.ts***
@ViewChild('paginator') paginator: MatPaginator;
resetPaginator() {
this.paginator.firstPage();
}
But as this.paginator is undefined, I cannot access paginator in the child component. I am not sure how can I access the paginator from parent. One way maybe using the following approach, but if there is an elegant way I would prefer it. Any idea?
@ViewChild(ChildComponent) child: ChildComponent;