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

依然范特西╮ 提交于 2021-02-10 15:47:21

问题


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:


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"


来源:https://stackoverflow.com/questions/64441455/angular-stricttemplates-how-to-set-boolean-and-numbers-in-templates-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!