0
I have the following repeat structure:
TS
resposta: string[];
HTML:
<ion-card *ngFor="let pergunta of perguntas; let i = index">
I have an ngModel that I need to print its value at its value:
<ion-textarea name="resposta" [(ngModel)]="resposta[i]" value="{{resposta}}" placeholder="Resposta" clearInput></ion-textarea>
But I get:
Cannot read Property '0' of Undefined
If I do it: [(ngModel)] = "answer" all goes well, but my other elements also receive the value I put in this field.
tries to put a *ngIf="response" on the component. Since the component is started empty it does not have the 0 position of the array.
<ion-textarea *ngf="resposta" name="resposta" [(ngModel)]="resposta[i]" value="{{resposta}}" placeholder="Resposta" clearInput></ion-textarea>
– Lucas Brogni
But it needs to be initialized, even if empty, as it is an input field...
– veroneseComS
Try initializing it with:
resposta: string[] = [""];
– Lucas Brogni