Angular: strictTemplates - How to set boolean and numbers in Templates properly?

4.9k views Asked by At

I set strictTemplates:true and use in a HTML template the following

<textarea matInput matAutosizeMaxRows="4" matTextareaAutosize="true"

I receive from the compiler

 error TS2322: Type 'string' is not assignable to type 'number'.
 error TS2322: Type 'string' is not assignable to type 'boolean'.

But how to set it properly in the HTML-Templates (to avoid the error)?

1

There are 1 answers

3
JSON Derulo On BEST ANSWER

Wrap the property name in brackets. If you leave the brackets, the values will be interpreted as strings. With brackets, the values are interpreted as TypeScript, and are therefore typed properly.

<textarea matInput [matAutosizeMaxRows]="4" [matTextareaAutosize]="true"