Angular:strictTemplates-如何在模板中正确设置布尔值和数字? [英] Angular: strictTemplates - How to set boolean and numbers in Templates properly?

查看:96
本文介绍了Angular:strictTemplates-如何在模板中正确设置布尔值和数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<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模板中正确设置它(以避免错误)?

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

推荐答案

将属性名称括在方括号中.如果不放在方括号中,则这些值将被解释为字符串.使用括号将值解释为TypeScript,因此可以正确键入.

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"

这篇关于Angular:strictTemplates-如何在模板中正确设置布尔值和数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆