Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

angular - How can I access FormArray element values?

<div [formGroup]="certificateForm">
<div formArrayName="certificateTextPlacements" *ngFor="let certificateTextPlacement of certificateTextPlacements().controls; let i = index;">

  <div
    [formControlName]="i"
    [ngStyle]="{
      'margin-left': certificateTextPlacement.xPos+'px',
      'margin-top': certificateTextPlacement.get('YPos').value+'px',
      'position': 'absolute',
      'font-size': '22px',
      'z-index': 10,
      'background-color': certificateTextPlacement.get('backgroundColour').value
    }"> [[ {{ certificateTextPlacement.get('name').value }} ]] </div>
</div>

Is there a particular method to use when looping through a FormArray to access an array items property value?

I want to access each array items property value of 'xPos', 'yPos', 'name' and 'backgroundColour'

EDIT - I fixed this by removing [formControlName]="i" and now certificateTextPlacement.get('YPos').value works

question from:https://stackoverflow.com/questions/65936732/how-can-i-access-formarray-element-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remove [formControlName]="i"

Use: certificateTextPlacement.get('yPos').value to access values


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...