I'm trying to create a dynamic number of text inputs and bind each to a value in an array of strings in object a. This seems to generate weird issues. Every letter I type into a textbox unselects the textbox, and unpredictable things happen when I add new items to the list. Any ideas what is going on?
Template:
<div *ngFor="let listItem of a.list; let i = index;">
<input type="text" name="sourceText" id="sourceText" class="form-control"
placeholder="Enter item" required [(ngModel)]="a.list[i]">
</div>
<a (click)="a.list.push('')">Add new item...</a>
Typescript:
export class MyClass {
a: { list: string[] };
constructor() {
this.reset();
}
reset() {
this.a = {list: ['']};
}
}