如何检索NgModelGroup
嵌套在 中的的验证状态NgFor
?
如果我没有NgFor
,我可以将组分配给这样的模板变量:
<p *ngIf="addressCtrl.invalid">Address is invalid.</p>
<div ngModelGroup="address" #addressCtrl="ngModelGroup">
<input name="city" [ngModel]="address.city" required>
<input name="state" [ngModel]="address.state" required>
<input name="zip" [ngModel]="address.zip" required>
</div>
但相反,我想要这样的东西:
<p *ngIf="addressCtrl.invalid">Address # {{index}} is invalid.</p>
<div *ngFor="let address of addresses">
<div ngModelGroup="address" #addressCtrl="ngModelGroup">
<input name="city" [ngModel]="address.city" required>
<input name="state" [ngModel]="address.state" required>
<input name="zip" [ngModel]="address.zip" required>
</div>
</div
问题是我得到addressCtrl
的是未定义的。
这是我创建的用于测试它的 plunker:https ://plnkr.co/edit/RXi2T52kynsWLr4fDMVa?p=preview