0

I want to use data that has been set in an array to bind to specific input boxes. with this piece of code, I get an error:

Recommendation.question contains an array of questions that has been loaded through a service. This works fine, and also if just show the value of question by using the brackets it works. Just the value of the array won't bind to the input box.

The error I Get:

Unhandled Promise rejection: Cannot assign to a reference or variable! ; Zone: <root> ; Task: Promise.then ; Value: ZoneAwareError Error: Cannot assign to a reference or variable!

  <div class="list-group-item"
    *ngFor="let question of Recommendation.question; let i = index;">
    <input class="form-control" name="question" [(ngModel)]="question"/>
    {{question}}
    {{i}}
  </div>

if I comment out the input field, the {{question}} shows the correct value that is at the current index of the array.

0

1 Answer 1

1

The problem should lie with that the [(ngModel)] variable is the same as the reference in the iteration, meaning question.

Doing this should work:

<div class="list-group-item"
  *ngFor="let question of Recommendation.question; let i = index;">
  <input class="form-control" name="question" [(ngModel)]="Recommendation[i]"/>
  {{question}}
  {{i}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.