【发布时间】:2018-07-24 20:17:02
【问题描述】:
将 ngModel 分配给 ngFor 中的模板变量时,该值未定义。它已在 Angular 存储库 here 中提出,但已经一年多了,似乎没有解决方案。有人有解决方案或解决方法吗?看来这应该是一个普遍的问题。
<tr *ngFor="let desc of descriptions; let i = index">
<td>
<my-input required name="description" #description="ngModel" [maxlength]="400" class="edit-input" type="text" [(ngModel)]="desc.description"></my-input>
<label *ngIf="isRequired(description)" class="required-label">{{'required' | translate}}</label>
<ng-template #readOnly><p>{{ desc.description }}</p></ng-template>
</td>
</tr>
【问题讨论】:
-
如果你
[(ngModel)]="descriptions[i].desc.description" -
仍然返回 undefined 与这两个。