this.queuingForm.get('services').get('englishName').setValue(this.storeServices[i].englis…
- User
this.queuingForm.get('services').get('englishName').setValue(this.storeServices[i].englishName) services is array and englishName is array attribute i want to set value console gives error
- Assistant
It seems like there may be a misunderstanding in your code. Based on the error you are getting, I suspect that
this.queuingForm.get('services')is actually an array instead of an object. If this is the case, you cannot call theget()method on it to retrieve another array namedenglishName.To set the
englishNamevalue for each service in the array, you need to loop through theservicesarray and set the value for each element individually. Here's an example of how you can achieve this:for(let i = 0; i < this.storeServices.length; i++) { this.queuingForm.get('services').at(i).get('englishName').setValue(this.storeServices[i].englishName); }In this code snippet,
this.queuingForm.get('services').at(i)is used to access thei-thelement in theservicesarray, and thenget('englishName')is used to set theenglishNamevalue for that particular element.Make sure to adjust the above code according to the structure of your
queuingFormandservicesarray to fit your specific requirements. - User
Property 'at' does not exist on type 'AbstractControl'.
- Assistant
Apologies for the mistake. It seems like the
at()method is not available directly on theAbstractControlinterface in Angular. Instead, you can use thecontrolsproperty to access the controls within a FormArray.Here's an updated code snippet that should work:
const servicesArray = this.queuingForm.get('services') as FormArray; for (let i = 0; i < this.storeServices.length; i++) { const serviceGroup = servicesArray.at(i) as FormGroup; serviceGroup.get('englishName').setValue(this.storeServices[i].englishName); }In this modified code, we first cast
this.queuingForm.get('services')to aFormArraytype and then access the individual FormGroup at indexiusingat(i). Finally, we set theenglishNamevalue for each individual service.Please ensure that
this.queuingForm.get('services')is indeed a FormArray in your form structure for this code to work correctly. Adjust the code according to the specific structure of your form if needed.