Sampath
Sampath

Reputation: 65870

ion-select with form builder doesn't show correct value

.html

 <ion-select formControlName="type">
    <ion-select-option value="t?.id" *ngFor="let t of (issueTypes$ | async)?.result;"> {{t?.name}}
   </ion-select-option>
  </ion-select>

.ts

  init() {
    this.form = this.formBuilder.group({
      type: ['', Validators.required],
     });
  } 

 save() {
   const maintenance: Maintenance = {
      type: this.form.value.type,
     };
  }

Debug

enter image description here

Why type shows t?.id as value?

Upvotes: 0

Views: 21

Answers (1)

jcuypers
jcuypers

Reputation: 1794

you need to bind the value. like so

<ion-select-option [value]="t?.id" *ngFor="let t of (issueTypes$ | async)?.result;"> {{t?.name}}

also: i think you need to fetch your form data as:

this.<FORM>.get('<FIELD>').value

Several other items need to be set correctly in order for this to work. please post full form code if you need more assistance

Upvotes: 1

Related Questions