Ich habe Komponente, die ein Formular und einige untergeordnete Komponenten innerhalb des Formulars hat. Die untergeordneten Komponenten werden mit *ngFor
erstellt und jedes untergeordnete Element enthält input
Elemente. Angular2 Compiler gibt Fehler wie [FormGroup] ist nicht definiert.Angular 2: Formular enthält untergeordnete Komponente
Ist diese Implementierung korrekt?
Geordnete Komponente:
<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>
Kinder Komponente: 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>
P. S. : Alle Importe sind gut, so bin ich mir ziemlich sicher, dass keine Importfehler hier
Es gibt einen kürzlichen Blogpost, der ein Beispiel dafür zeigt. Sie können es hier finden: https://toddmotto.com/component-architecture-reactive-forms-angular – DeborahK