Lets say i have a checkbox and each checkbox has a categoryId. When i check the checkbox i will get the categoryId and each data will be save as a formArray, example at index 0:
and this is the result i want to get
CodePudding user response:
convertValue(){
const values = this.form.get('hubxCategoryId').value;
//values is an array [true,true,false,...]
return this.hubxReport
//filter gets [{hubxCategoryId:2,categoryName:".."},
// {hubxCategoryId:6,categoryName:".."},..]
.filter((x, index) => values[index])
//maps return only the "Id" [2,6,...]
.map(x=>x.hubxCategoryId)
//join return an string "2,6,..."
.join(",")
}
But take a look to this SO, you not create a FormArray else a FormControl that store an array
CodePudding user response:
Try this: let desiredFormat= this.patientReportForm.value.hubxCategoryId.join(",")