Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 767
LeO Avatar asked Oct 20 '20 08:10

LeO


People also ask

Which feature will enable type identification on the template in Angular?

Full modelink. If the fullTemplateTypeCheck flag is set to true , Angular is more aggressive in its type-checking within templates.

Does Angular have template type checking?

To be more precise, Angular creates Type Check Blocks (TCBs) based on the component template. Basically, a Type Check Block is a block of TypeScript code which can be inlined into source files, and when type checked by the TypeScript compiler will give us information about any typing errors in template expressions.

Which of the following tags is not supported by the Angular template?

To eliminate the risk of script injection attacks, Angular does not support the <script> element in templates. Angular ignores the <script> tag and outputs a warning to the browser console.


1 Answers

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"
like image 167
JSON Derulo Avatar answered Nov 15 '22 01:11

JSON Derulo