I'm trying to develop an angular application. I am dynamically generates input html element using ngFor from an array and I am giving the ID for the element as inputElem_{{index}}. If I'm trying to delete second last element and add new element I am getting two element with same name and value given in the both input box are getting emptied and showing as invalid in ui
<i class="fa fa-add" (click)="addElem()"></i>
<div class="row" *ngFor="let elemName of elemList; let index=index;">
<div class="col-md-8">
<input id="inputElem_{{index}}" name="inputElem_{{index}}" required
[(ngModel)]="elemName.name"/>
</div>
<div class="col-md-2">
<i class="fa fa-delete" (click)="deleteElem(index)"></i>
</div>
</div>
deleteElem(index: number) {
this.elemList.splice(index, 1);
}
addElem() {
const elem = new Elem();
this.elemList.push(elem);
}