Angular:strictTemplates-如何在Templates中正确设置布尔值和数字



我设置strictTemplates:true并在HTML模板中使用以下

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

我收到来自编译器的

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

但是如何在HTML模板中正确设置它(以避免错误(?

将属性名称括在括号中。如果保留括号,则这些值将被解释为字符串。使用方括号,值将被解释为TypeScript,因此类型正确。

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

最新更新