textarea 在 angular6 中不起作用
textarea does not work in angular6
我正在使用 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"
,没有问题。
我错过了什么?
谢谢
编辑
我忘了说我想在文本区域中有换行符和 link,比如
Hi there ,
this is the code you have to use
Click here
我想要换行,Click here
必须是 link
如果我这样做
mailtext:any;
this.mailtext = 'Hi there,'+<br>+'this is the code you have to use';
我得到Hi there,NaN
谢谢
它可能在运行时被 ngModel
绑定替换。
如果要有默认值,只需在组件中设置this.mailtext = 'Hi there'
我正在使用 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"
,没有问题。
我错过了什么?
谢谢
编辑
我忘了说我想在文本区域中有换行符和 link,比如
Hi there ,
this is the code you have to use
Click here
我想要换行,Click here
必须是 link
如果我这样做
mailtext:any;
this.mailtext = 'Hi there,'+<br>+'this is the code you have to use';
我得到Hi there,NaN
谢谢
它可能在运行时被 ngModel
绑定替换。
如果要有默认值,只需在组件中设置this.mailtext = 'Hi there'