【发布时间】:2019-06-20 22:31:00
【问题描述】:
考虑同一模板内的以下情况:
<!-- createFoo -->
<form [formGroup]="fooForm1" (ngSubmit)="createFoo(fooForm1)">
<input formControlName="bar">
</form>
<!-- updateFoo -->
<form [formGroup]="fooForm2" (ngSubmit)="updateFoo(fooForm2, index)">
<input formControlName="bar">
</form>
如果不在同一个模板中定义相同的一组表单/formControls,我将如何重新编写它?
我相信它需要看起来像这样? >>>
<!-- createFoo -->
<ng-template [ngTemplateOutlet]="fooForm" [ngTemplateOutletContext]="..."></ng-template>
<!-- updateFoo -->
<ng-template [ngTemplateOutlet]="fooForm" [ngTemplateOutletContext]="..."></ng-template>
<ng-template #fooForm>
<form [formGroup]="...." (ngSubmit)="....">
<input formControlName="bar">
</form>
</ng-template>
【问题讨论】:
标签: angular ng-template