如何将FormControl与ngComponentOutlet一起使用 - Angular 5

时间:2018-03-07 08:47:21

标签: angular angular-reactive-forms reactive-forms ng-component-outlet

我正在尝试使用formControl加载动态组件,但它不会影响我的主机formGroup。

试过这些选择:

模板:

选项1 - 不工作:

 <div [formGroup]="form">
    <ng-container *ngComponentOutlet="getComponent()" [formControlName]="getFormControlName()"></ng-container>
 </div>

选项2 - 不工作:

<div [formGroup]="form">
    <ng-container *ngComponentOutlet="getComponent()" [formControl]="getFormControl()"></ng-container>
</div>

选项3 - 工作:

<div [formGroup]="form">
    <my-dynamic-component [formControl]="dynamicFormControl"></my-dynamic-component>
</div>

组件功能:

getComponent:返回动态组件(支持使用reactiveForm)

getFormControlName:返回formControl名称。返回字符串

getFormControl:返回formControl对象。 FormControl

有人知道我应该怎么做?这可能吗?

查看该示例: https://stackblitz.com/edit/angular-n8sdrm?embed=1&file=app/app.component.html

由于

0 个答案:

没有答案
相关问题