【发布时间】:2018-07-08 17:02:03
【问题描述】:
我正在使用 Angular 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
谢谢
【问题讨论】:
-
它可能在运行时被
ngModel绑定所取代。如果你想有一个默认值,只需在组件中设置this.mailtext = 'Hi there' -
@user184994 很棒的收获。把它变成一个常规的答案,这样我就可以把它设置为接受了
标签: angular forms textarea angular6