angular 2设置表单值并在反应形式内呈现html组件

时间:2018-03-08 03:18:34

标签: html5 angular forms angular-reactive-forms ng-bind-html

所以我在表单中有一个<textarea>

HTML

  <form novalidate [formGroup]="formGroup" (ngSubmit)="onSubmit()">
     <textarea   formControlName="content" [rows]="5"><textarea>

我正在设置表单内的内容值。

打字稿

  this.formGroup.setValue(
        {
          'submitterTolist':  this.result.submitterlist,
          'reviewerTolist':   this.result.reviewerlist,
          'attesterTolist':   this.result.attesterlist,
          'mailCclist':       this.result.email_cc,
          'strsubject':       this.result.subject,
          'content':          this.result.content
        }

我面临的问题是内容值为html我需要在<textarea>元素中呈现,而不是仅将文本显示为html

以下是内容示例:

<p>Kindly be  informed that the resubmission of Monthly Actuals data for Mexico Internal Fraud Others for Nov 2017 has been approved by the Regional Oversight Manager in the  Enterprise Risk - Fraud Capture Application.</p> <p>The following comments have been provided:</p> Approved. Citirisk Team provided the data to be uploaded. <p>Thank You</p>

1 个答案:

答案 0 :(得分:0)

您无法在文本区域中呈现html。您可以添加div元素并使用属性biding来设置innerHTML属性。

<div [innerHTML]="theStringWithHtmlTags"></div>