Gordon Hickley
Gordon Hickley

Reputation: 491

Angular reactive form in array, how to get formcontrolnames?

<div *ngFor="let reply of repliesForm?.get('replies')?.value; let i = index;">
    <div [innerHTML]="reply.body"></div>
    <textarea formControlName="reply.body"></textarea>
</div>

The innerHTML is set fine but how do I get the formControlName to bind to the textarea?

Upvotes: 0

Views: 75

Answers (2)

Chiranjaya Denuwan
Chiranjaya Denuwan

Reputation: 683

I think this will work fine for you

<div *ngFor="let reply of repliesForm?.get('replies')?.value; let i = index;">
  <div [innerHTML]="reply.body"></div>
  <textarea formControlName="{{reply.body}}"></textarea>
</div>

Upvotes: 0

HungCung
HungCung

Reputation: 188

I think you should change your loop like this. Because you can access both value and control.

<div *ngFor="let replyControl of repliesForm?.get('replies'); let i = index;">
    <div [innerHTML]="replyControl.value.body"></div>
    <textarea [formControl]="replyControl"></textarea>
</div>

Upvotes: 1

Related Questions