What is the common way to use @ViewChild in Angular strict mode?
For example, when I take the code for sorting a Material table as described in documentation
@ViewChild(MatSort) sort: MatSort;
The compiler says:
error TS2564: Property 'sort' has no initializer and is not definitely assigned in the constructor.
As a possible solution I could use
@ViewChild(MatSort, { static: false }) sort!: MatSort;
... but that seems to me more like a workaround.
It appears to be correct to remomve the { static: false } part. So a valid declaration for sort would be:
@ViewChild(MatSort) sort!: MatSort;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With