首页 > 解决方案 > 如何在反应式表单控件中使用 html 标签?

问题描述

我有这样的事情:

this.emailForm=new FormGroup({
      outcomeSubject: new FormControl('Hi<br />My name is John', Validators.required),
      outcomeNotes: new FormControl('<div>Hi</div><div>My name is John</div>', Validators.required)
    })

元素是文本区域。如何在文本区域内设置标签?我尝试使用 innerHTML 失败,但仍然看到 html 标签。

提前致谢!

标签: angularangular-forms

解决方案


就我而言,我找到了一个简单的解决方案,例如

const htmlStr = 'text1\ntext2\ntext3';
this.emailForm=new FormGroup({
      outcomeSubject: new FormControl(htmlStr, Validators.required),
      outcomeNotes: new FormControl(htmlStr, Validators.required)
    })

推荐阅读