[英]Input filed is not working properly in place of ngFor
Values entered by the user inside a given input field shows only one letter. 用户在给定的输入字段中输入的值仅显示一个字母。 Can anyone please help.
谁能帮忙。
https://stackblitz.com/edit/angular-8kpyxt?file=src%2Fapp%2Fapp.component.html https://stackblitz.com/edit/angular-8kpyxt?file=src%2Fapp%2Fapp.component.html
Use trackBy 使用trackBy
The trackBy function takes the index and the current item as arguments and needs to return the unique identifier for this item
trackBy函数将索引和当前项目作为参数,并需要返回该项目的唯一标识符
component.html component.html
<div class="form-group" *ngFor="let Type of type.headings;trackBy: cmpare;let i=index">
<label>Heading{{i+1}}</label>
<input type="text" class="form-control" [name]="'name1_'+i" [(ngModel)]="type.headings[i]">
</div>
component.ts component.ts
cmpare(index) {
return index;
}
Example: https://stackblitz.com/edit/angular-uwfphr Ref: https://angular.io/api/common/NgForOf#change-propagation 示例: https : //stackblitz.com/edit/angular-uwfphr参考: https : //angular.io/api/common/NgForOf#change-propagation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.