1
我在使用ngForFor從input type =「text」獲取值時存在問題,而我將它與[(ngModel)]綁定時,它們都具有相同的值我可以在ngFor中綁定所有輸入嗎?如何從input type =「text」在循環ng中獲取輸入值對於
HTML
<button (click)="saveFeature()" type="button">save</button>
<input class="form-control" type="text" />
<button (click)="addFeature()" type="button">Add</button>
<div *ngFor="let inputservice of servicesfeature_id; let i=index">
<input class="form-control" [(ngModel)]="listServiceFeature" type="text" />
<button (click)="RemoveFeature(i)" type="button">Remove</button>
</div>
組件
servicesfeature_id: any = [];
servicesfeature_length: number = 0;
listServiceFeature: any = [];
servicefeature_name: string;
saveFeature(): void {
console.log(this.listServiceFeature);
}
addFeature(): void {
this.servicesfeature_id.push('service' + this.servicesfeature_length);
this.servicesfeature_length += 1;
}
RemoveFeature(index): void {
this.servicesfeature_length -= 1;
this.servicesfeature_id.splice(index, 1);
}
這裏是代碼plnkr.co