textarea在angular6中不起作用

时间:2018-07-08 17:02:04

标签: angular forms textarea angular6

我正在使用角度6,并且尝试将文本区域放入表格中。

到目前为止,这是我的代码

<textarea rows="20" cols="50" id="mailtext" required [(ngModel)]="mailtext" name="mailtext" #mailtextvalidityMsg="ngModel" >Hi there</textarea>

我可以在html中看到文本区域,但是未呈现“ Hi there”文本。我的控制台没有任何错误。

如果我删除了[(ngModel)]="mailtext" name="mailtext" #mailtextvalidityMsg="ngModel",它将起作用。

这仅在文本区域中发生。对于具有相同格式的其他字段,例如input type="email",没有问题。

我想念什么?

谢谢

编辑

我忘了提到我想在文本区域中使用换行符和链接,类似

Hi there , 

this is the code you have to use 

Click here

我想换行,Click here必须是链接

如果我这样做

mailtext:any;
this.mailtext = 'Hi there,'+<br>+'this is the code you have to use';

我得到Hi there,NaN

谢谢

1 个答案:

答案 0 :(得分:1)

它可能已在运行时替换为ngModel绑定。

如果要使用默认值,只需在组件中设置this.mailtext = 'Hi there'

相关问题