11

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)?

LeO
  • 4,238
  • 4
  • 48
  • 88
  • You could use the square-bracket attribute-binding notation (`[attribute]="value"`). (See the [Angular docs on binding syntax](https://angular.io/guide/binding-syntax) for more info) – Edric Oct 20 '20 at 08:39

1 Answers1

17

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"
JSON Derulo
  • 9,780
  • 7
  • 39
  • 56
  • thx for the reply. Is there a general guide how to treat HTML variable now 'newly'? I'm facing similar problems with $events or enums – LeO Oct 20 '20 at 08:59
  • All values expect strings should use the bracket notation. For events you need to take care that the parameters of the event handling function are typed properly. But without code it's hard to tell what is the issue. Maybe add a new question? – JSON Derulo Oct 20 '20 at 09:03
  • Perhaps you have an idea as well for https://stackoverflow.com/questions/64445660/angular-stricttemplates-how-to-assign-variables-properly – LeO Oct 20 '20 at 12:58