我有一個組件,它有一個窗體和表單中的一些子組件。子組件使用*ngFor
創建,每個子組件包含input
個元素。 Angular2編譯器給出的錯誤類似[formGroup]沒有定義。Angular 2:包含子組件的表單
此實現是否正確?
父組件:
<section class="data-body">
<form [formGroup]="checkoutForm" novalidate>
<app-checkout-product-view *ngFor="let item of checkoutData.products" [_product]="item" formGroupName="products"></app-checkout-product-view>
<div class="col-md-4">
<label>Nominee:</label>
<select required [(ngModel)]="checkoutData.selectedNominee" [ngModelOptions]="{standalone: true}">
<option *ngFor="let nominee of checkoutData.nomineeList" [value]="nominee">{{nominee}}</option>
</select>
</div>
<div class="col-md-4">
<label>Bank Account:</label>
<select [(ngModel)]="checkoutData.selectedBank" required [ngModelOptions]="{standalone: true}">
<option *ngFor="let bank of checkoutData.bankList" [value]="bank">{{bank}}</option>
</select>
</div>
</div>
</form>
</section>
子組件:app-checkout-product-view
<div class="row">
<div class="col-md-4">
<md-input required [(ngModel)]="product.investmentAmount
formControlName="investmentAmount">
<span md-prefix>₹</span><!--Rupee icon-->
</md-input>
</div>
</div>
附: :所有的進口都很好,所以我很確定這裏沒有進口錯誤
還有一篇最近的博客文章也是這樣的例子。你可以在這裏找到它:https://toddmotto.com/component-architecture-reactive-forms-angular – DeborahK