【发布时间】:2020-05-26 14:49:40
【问题描述】:
我正在使用 Angular 9 中的反应形式。 我想要可重复使用的表格。因此,我为表单创建了一个单独的组件。 但我不知道如何将表单值传递给其他组件无需单击表单组件,因为我希望每个组件都有单独的按钮。 如何在 app.component 中编写发送函数?
form.component.html
<form [formGroup]="form">
<div *ngFor="let prop of personProps">
<label>{{ prop.label }}:</label>
<div [ngSwitch]="prop.type">
<input *ngSwitchCase="'text'" [type]="prop.type" [formControlName]="prop.key">
<input *ngSwitchCase="'number'" [type]="prop.type" [formControlName]="prop.key">
</div>
</div>
</form>
app.component.html
<dynamic-form [formDataObj]="person"></dynamic-form>
<button (click)="send()"> click </button>
【问题讨论】:
标签: angular