Suhayb
Suhayb

Reputation: 3271

How to query lazy loaded material tab using ViewChild

I am trying to query a MatPaginator using ViewChild, it's located in a lazy loaded mat-tab-group, but I got undefined, even though if I invoked it after focusing on the target tab holding the element using (selectedTabChange)

Please have a look into this stackblitz element is in the third tab focus on it and check the console log.

Upvotes: 0

Views: 687

Answers (1)

yurzui
yurzui

Reputation: 214195

You should be using dynamic query so that Angular will update the query once paginator is loaded:

 @ViewChild("paginator", { static: false }) paginator: MatPaginator;
                                   ^^^^^

And make sure you are invoking the query when the tab is selcted using selectedTabChange

Upvotes: 2

Related Questions