【发布时间】:2017-03-03 12:09:45
【问题描述】:
我有一个组件,它有一个表单和表单内的一些子组件。子组件是使用*ngFor 创建的,每个子组件都包含input 元素。 Angular2 编译器给出了诸如 [formGroup] 未定义之类的错误。
这个实现是否正确?
父组件:
<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>
附: : 所有的导入都很好,所以我很确定这里没有导入错误
【问题讨论】: