Here is my model object from model.ts
name_id: string[]; public generateUrlencodedParameters(token: string, id?: number): string {
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('name_id', this.name_id.toString());
Now moving to component.ts
this.MyForm = new FormGroup({
'name_id': this.fb.array([])
});
onAddItem() {
(<FormArray>this.MyForm.controls['name_id']).push(new FormControl('', Validators.required)); }
Lastly, in the component.html file
<div class="row">
<div formArrayName="name_id">
<div class="form-group" *ngFor="let name of MyForm.get('name_id').controls; let name_id = index">
<br>
<input class="form-control" formControlName="{{name_id}}">
</div>
</div>
<div class="input-field col s4">
<button type="button" class="btn btn-primary" (click)="onAddItem ()">+</button>
</div> </div>
I am facing an issue where when I post it to the webservice, it gets formatted as
name_id=FA163EBBBC1D%2C11E7FF6%2C11E7FF6FC1D
, separating the array with %2C
. Can anyone help me with this problem?