嗨,我有类似以下的代码
<div *ngFor="let phone of phoneList; let phIndx = index;">
<div class="peoplePhoneTxtDiv">
<input [disabled]="phone.disabled" class="peoplePhoneTxtBox" type="text" name={{phone.no}}+"phIndx"
[value]="phone.no" [(ngModel)]="phone.no" required>
</div>
</div>
我需要使texbox名称动态地由字符串+索引组成。如果texbox名称相同,则当我更改一个值时,所有内容都会更改。因此,我尝试如图所示进行操作,但是出现了错误,请帮助。
答案 0 :(得分:0)
尝试name="{{phone.no + phIndx}}"
或[name]="phone.no + phIndx"
<div *ngFor="let phone of phoneList; let phIndx = index;">
<div class="peoplePhoneTxtDiv">
<input [disabled]="phone.disabled" class="peoplePhoneTxtBox"
type="text" name="{{phone.no+phIndx}}"
[value]="phone.no" [(ngModel)]="phone.no" required>
</div>
</div>