Reputation: 427
I am trying to make a list of inputs and I can't get ngFor to compile.
<div *ngFor="let q of questions; let i = index" class="col-3">
<div class="group">
<input [(ngModel)]="q" [class.ng-not-empty]="q.length > 0">
<span class="bar"></span>
<label>Question {{i}}</label>
</div>
</div>
my definitions are set as such:
questions: string[];
constructor() {
this.questions = ['blah', 'blah', 'blah'];
}
the error i get is:
ERROR in : Error: Cannot assign to a reference or variable!
If I remove the index definition it works and i have tried all of the following:
*ngfor="let q of questions | index as i"
*ngfor="let q of questions; index as i"
Upvotes: 0
Views: 731
Reputation: 1905
You can't use [(ngModel)]="q"
because you are trying to assign to a local variable in your HTML (in this case, let q
)
Try this:
[(ngModel)]="questions[i]";
Upvotes: 6