首页 > 解决方案 > 角度启动抛出错误中的自动调整大小

问题描述

当我尝试使用 autoresize 属性时,出现一个错误: Type 'string' is not assignable to type 'boolean'

模板代码是: <textarea [rows]="5" [cols]="30" id="float-input3" pInputTextarea autoResize="true"></textarea>

我像在文档中一样使用这个属性,我不知道什么不起作用。

我已经尝试使用autoResize="autoResize"但我有同样的错误。

文档https://www.primefaces.org/primeng/showcase/#/inputtextarea

你知道什么不起作用或我做的不对吗?

我使用 Primeng 11.2.0 和 Angular 11。

谢谢你的帮助

标签: angulartextareaprimengautoresize

解决方案


Pretty sure you need to add a new public property to your component:

public autoResize: boolean = true;

...and then bind it into the template like:

<textarea ... [autoResize]="autoResize"></textarea>

In your examples you didn't have the [ ] around the property. Angular was getting confused as to whether you wanted to pass "true" as a string or true as a boolean. When it is explicitly defined in the component with :boolean, angular can be assured of what the type is.


推荐阅读