【发布时间】:2020-06-25 08:45:30
【问题描述】:
我在我的 Angular 应用程序中使用子组件和父组件。我想从父组件设置我的子组件中的输入元素的值。我从 api 获取数据,我想在我的子组件中设置的值是“HTML”类型。我该怎么做。请指导我。
注意:我能够从父组件获取数据到子组件。我想知道如何使用 formControl 将 HTML 格式的值传递给我的子组件并显示它。
HTML 父组件
<form[formGroup]='parentForm'>
<childComponent [childForm]= "parentForm.controls.childForm" ></childComponent>
</form>
HTML 子组件
<form[formGroup]='childForm'>
<div>
<input [innerHtml] = "test" formControlName = "childttest">
</div>
</form>
TS
ngOnInit() {
this.parentForm = this.FormBuilder.group({
test1: [''],
childForm: this.FormBuilder.group({
childtest: ['']
})
});
// data contains HTML code. i want to display only text not HTML.
this.parentForm.controls.childForm.controls.childtest.setValue(this.data);
}
【问题讨论】:
标签: angular angular-reactive-forms