I'm coding in Visual Studio Code
an Angular 8
project and just added some strict mode configuration:
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
Now, my paginator which was working fine, now is not even compiling.
I can instantiate the MatSort with:
@ViewChild(MatSort, { static: true }) sort: MatSort = new MatSort();
But I cannot do the same for the MatPaginator member variable:
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
This forces me to add some checks in the code:
if (this.paginator) {
I read this blog article but I'm still searching for an alternative solution.
The paginator in the view:
<mat-paginator [pageIndex]="currentPageNumber" [length]="totalElements" [pageSize]="elementsPerPage" [pageSizeOptions]="pageSizeOptions" [showFirstLastButtons]="true"></mat-paginator>
It is not within an ngIf
directive.