Skip to content
Advertisement

How to access the properties of a formArray in HTML?

I’m trying to implement a reactive Angular form, but, I can’t access the properties of the array on HTML, I never worked with reactive form, if anyone could guide me I would be grateful! I’m using Angular 10 and I have the following code:

TS

JavaScript

HTML

JavaScript

Models

JavaScript

error-handler.service.ts:87 Error: Cannot find control with path: ‘workStations -> 0 -> rank’ @ undefined:undefined

NOTE: I already looked at some answers here on the site such as this, this and this , but none of them solved this problem!

Advertisement

Answer

your problem is here :

JavaScript

you are passing an array of IScriptOperationOrdersModel instead of array of form group.
To make your code working, you have to loop on every element of this.operationModel.scriptOperationOrders array , and instanciate a new FormControl object then push it in the workStations form array.
To access its elements, you can use controls[indexOfGroup].rate

You can take a look at this simple example you will understand everything.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement