2
votes

I have a form in Angular, the select option has data coming from a web api. What I want to know is how to assign the selected value to form value when sending at the moment it is just [object object]. The ngFor statement is:

<select class="form-select" formControlName="u_address" placeholder="Enter address">
   <option value="" disabled selected>Select your option</option>
   <option *ngFor="let item of customerAddress" [value]="item">
   {{item.address}}
   </option>
</select>

Then in the component.ts file it is:

  u_address: new FormControl(this.customerAddress),

Any ideas?

2
Could you share your customerAddress object?Shohel

2 Answers

3
votes

Please use ngValue instead of value.

<select class="form-select" formControlName="u_address" placeholder="Enter address">
   <option value="" disabled selected>Select your option</option>
   <option *ngFor="let item of customerAddress" [ngValue]="item">
   {{item.address}}
   </option>
</select>
2
votes

Just try to the following code

[value]="item.address"

<select class="form-select" formControlName="u_address" placeholder="Enter address">
   <option value="" disabled selected>Select your option</option>
   <option *ngFor="let item of customerAddress" [value]="item.address">
   {{item.address}}
   </option>
</select>