I'm trying to add multiple input text fields for a description that is being assigned to an array, but I'm having trouble using ngModel here. In the code below, when typing into the textbox it loses focus and I can only type one character at a time -- almost like its lagging. It seems to work when outputting the array to the console, however, when I add another text field element instead of the third element being blank it will return the previous value.
component.html
<div class="input-group mb-3" *ngFor="let descriptions of descriptionPool;let i = index">
<span class="input-group-text" id="inputGroup-sizing-lg">Description #{{ i + 1 }}</span>
<textarea class="form-control text-wrap" placeholder="Posts will use this description." [(ngModel)]="descriptionPool[i]" name="somename"></textarea>
<button class="btn btn-primary text-light" (click)="addDescriptionField(descriptionPool[i])"> + </button>
<button class="btn btn-primary text-light" (click)="delDescriptionField(i)"><i class="fas fa-trash-alt"></i></button>
</div>
component.ts
descriptionPool: Array<string> = [];
ngOnInit(): void {
this.descriptionPool.push('');
}
addDescriptionField(description: string) {
console.log('descriptions? ' + JSON.stringify(this.descriptionPool));
this.descriptionPool.push(description);
}
delDescriptionField(index: any) {
this.descriptionPool.splice(index, 1);
console.log('after deleting: ' + JSON.stringify(this.descriptionPool));
}
The delete function works as expected. :)