# Ion-selected doesn't show the selected option

**URL:** <https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985>\
**Category:** ionic-v3\
**Created:** [January 31, 2017, 8:52pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985 "2017-01-31T20:52:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tenonic](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tenonic/32/106501_2.png) [@tenonic](https://forum.ionicframework.com/u/tenonic)\
**Post date:** [January 31, 2017, 8:52pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/1 "2017-01-31T20:52:44Z")

</div>

Using model driven form to select default option, so `residence` is already set:

```
<ion-select formControlName="residence">
   <ion-option [value]='"0"'>{{freeCalcForm.controls.partyAName.value}}</ion-option>
   <ion-option [value]='"1"'>{{freeCalcForm.controls.partyBName.value}}</ion-option>
</ion-select>

```

I don’t see the selected value:  
 ![image](https://global.discourse-cdn.com/ionicframework/original/3X/e/3/e33e4d2cd16d758a7e836c455f5a83a1b4a9ab81.png)  
But clicking on the ion-select shows that the value is already selected correctly:  
 ![image](https://global.discourse-cdn.com/ionicframework/original/3X/a/7/a74e03e821583160f757ccc57fdbae11659ae9cb.png)

I tried selected=“true” and selected=“selected” on first option without any effect.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [January 31, 2017, 11:40pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/2 "2017-01-31T23:40:13Z")

</div>

Are you absolutely certain that the `residence` control has its initial value set to “Self” by the time the template accesses it (by which I pretty much mean “in the component constructor”)?

---

<div class="post-metadata">

**Author:** ![tenonic](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tenonic/32/106501_2.png) [@tenonic](https://forum.ionicframework.com/u/tenonic)\
**Post date:** [February 1, 2017, 12:10am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/3 "2017-02-01T00:10:01Z")

</div>

Not so “Self” but to “0”. Yes it is set. Setting it to “1” successfully sets the Spouse as the default in the dropdown, with same issue of not showing it before clicking the select.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 1, 2017, 12:11am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/4 "2017-02-01T00:11:17Z")

</div>

Is it possible that the double quotes are screwing things up? I still don’t really understand JavaScript’s type conversions.

IOW, does changing `[value]='"0"'` to `value="0"` change anything?

---

<div class="post-metadata">

**Author:** ![tenonic](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tenonic/32/106501_2.png) [@tenonic](https://forum.ionicframework.com/u/tenonic)\
**Post date:** [February 1, 2017, 12:25am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/5 "2017-02-01T00:25:31Z")

</div>

I already tried that. Same thing. Dropdown select is selected, but not shown.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 1, 2017, 12:40am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/6 "2017-02-01T00:40:08Z")

</div>

Can you work backwards from this example (it works for me in a scratch testbed)?

```auto
form: FormGroup;

  constructor(fb: FormBuilder) {
    this.form = fb.group({
      fruit: ["banana"],
    });
  }

```

```auto
  <form [formGroup]="form">
    <ion-select formControlName="fruit">
      <ion-option value="apple">apple</ion-option>
      <ion-option value="banana">banana</ion-option>
      <ion-option value="cherimoya">cherimoya</ion-option>
    </ion-select>
  </form>

```

“banana” is selected as expected.

---

<div class="post-metadata">

**Author:** ![tenonic](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tenonic/32/106501_2.png) [@tenonic](https://forum.ionicframework.com/u/tenonic)\
**Post date:** [February 1, 2017, 12:48am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/7 "2017-02-01T00:48:42Z")

</div>

its due to interpolation {{}} in the ion-option text…what a bummer…  
this works just fine:

```
 <ion-select formControlName="residence">
              <ion-option value='0'>0</ion-option>
              <ion-option value='1'>1</ion-option>
  </ion-select>
```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 1, 2017, 12:50am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/8 "2017-02-01T00:50:51Z")

</div>

Ah. It’s probably actually due to the way you’re referencing `controls` directly. That breaks. Instead try this:

`{{freeCalcForm.get('partyAName').value}}`

---

<div class="post-metadata">

**Author:** ![tenonic](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tenonic/32/106501_2.png) [@tenonic](https://forum.ionicframework.com/u/tenonic)\
**Post date:** [February 1, 2017, 1:03am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/9 "2017-02-01T01:03:58Z")

</div>

Same probelm with this:

```
         <ion-select formControlName="residence">
          <ion-option value='0'>{{freeCalcForm.get('partyAName').value}}</ion-option>
          <ion-option value='1'>{{freeCalcForm.get('partyBName').value}}</ion-option>
        </ion-select>
```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 1, 2017, 1:15am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/10 "2017-02-01T01:15:48Z")

</div>

I think you have hit [#8561](https://github.com/driftyco/ionic/issues/8561).

---

<div class="post-metadata">

**Author:** ![RyxMedia](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@RyxMedia](https://forum.ionicframework.com/u/RyxMedia)\
**Post date:** [February 24, 2017, 7:25pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/11 "2017-02-24T19:25:54Z")

</div>

Ran today in the exact same issue ☹  
The workaround in [#8561](https://github.com/driftyco/ionic/issues/8561) from 3dd13 didn’t work for me either.

---

<div class="post-metadata">

**Author:** ![calebswank11](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@calebswank11](https://forum.ionicframework.com/u/calebswank11)\
**Post date:** [March 9, 2017, 3:43pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/12 "2017-03-09T15:43:59Z")

</div>

Might be a little late to the game here, but ran into this issue today as well and I have come up with a workaround albeit not for all situations.

If in your TS file, you can push the options you want to an array variable, you can access them via interpolation and it adds to the form builder upon submission.

something like this in your TS  
`(for loop here)`  
`this.testArray.push(data[i]);`

in your HTML  
`<ion-option *ngFor="let item of testArray; let i = index " value="{{item}}" selected="i === 0">{{item}}</ion-option>`

simple solution but requires a little extra legwork. Frustrating that it doesnt work like expected.

---

<div class="post-metadata">

**Author:** ![martinsahayam](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@martinsahayam](https://forum.ionicframework.com/u/martinsahayam)\
**Post date:** [January 7, 2018, 3:06am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/13 "2018-01-07T03:06:08Z")

</div>

You solution worked perfectly for me after 2 days of struggle. Thank You!

---

<div class="post-metadata">

**Author:** ![SnkrsFind](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@SnkrsFind](https://forum.ionicframework.com/u/SnkrsFind)\
**Post date:** [January 24, 2018, 1:05am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/14 "2018-01-24T01:05:38Z")

</div>

Wao thank you so much. This answered my question about `ion-select` with formBuilder approach. now i do `array.map()` in the form init for the auto select of values present in the options. 🙏🙌

---

<div class="post-metadata">

**Author:** ![rguntha](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@rguntha](https://forum.ionicframework.com/u/rguntha)\
**Post date:** [March 11, 2018, 10:14am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/15 "2018-03-11T10:14:00Z")

</div>

I simply reset the values again in on the form object…  
async ionViewDidLoad(){  
await this.init();  
this.userDetailsForm.controls[‘institution’].setValue(this.institution);  
this.userDetailsForm.controls[‘campus’].setValue(this.firstTimeCampus);  
this.userDetailsForm.controls[‘college’].setValue(this.firstTimeCollege);  
this.userDetailsForm.controls[‘department’].setValue(this.firstTimeDepartment);  
this.userDetailsForm.controls[‘userStatus’].setValue(this.userStatus);  
this.userDetailsForm.controls[‘userType’].setValue(this.userType);  
this.userDetailsForm.controls[‘role’].setValue(this.role);  
}

This solution is working for me…

---

<div class="post-metadata">

**Author:** ![bourgeois247](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@bourgeois247](https://forum.ionicframework.com/u/bourgeois247)\
**Post date:** [March 14, 2018, 11:21pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/16 "2018-03-14T23:21:57Z")

</div>

This gave me the inspiration for my solution. Thanks!

The problem (I think) is that Ionic automatically decides what option to mark as `selected` only if the option’s `value` matches what you interpolate. Which is why @tenonic 's final solution worked.

With your solution, you manually decide when each option is selected. So if you don’t want to, you don’t have to put your options in an Array and loop for this to work. Say you have:

```auto
<ion-select [(ngModel)]="employment" placeholder="Are you employed?">
   <ion-option value="self-employed">Yes, I work for myself</ion-option>
   <ion-option value="employed">Yes, I work for a company</ion-option>
   <ion-option value="student">No, I'm a student</ion-option>
</ion-select>

```

By default, when you select any of these options, you won’t see your selected value, but once you do this, you should be good:

```auto
<ion-select [(ngModel)]="employment" placeholder="Are you employed?">
   <ion-option value="self-employed" selected="employment === 'self-employed'">Yes, I work for myself</ion-option>
   <ion-option value="employed" selected="employment === 'employed'">Yes, I work for a company</ion-option>
   <ion-option value="student" selected="employment === 'student'">No, I'm a student</ion-option>
</ion-select>

```

Cheers!

---

<div class="post-metadata">

**Author:** ![Krushn](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@Krushn](https://forum.ionicframework.com/u/Krushn)\
**Post date:** [May 14, 2018, 9:50am UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/17 "2018-05-14T09:50:12Z")

</div>

Adding timeout worked for me

```auto
setTimeout(_ => {
      this.form.controls.email_preference.setValue("Daily");
 })

```

---

<div class="post-metadata">

**Author:** ![MarkAurit](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@MarkAurit](https://forum.ionicframework.com/u/MarkAurit)\
**Post date:** [May 14, 2018, 2:21pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/18 "2018-05-14T14:21:49Z")

</div>

Super embarassing answer: in one case everything worked correctly - but my css was making the text the same color as the background. Hate when that happens.

---

<div class="post-metadata">

**Author:** ![peterpan666](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/peterpan666/32/119566_2.png) [@peterpan666](https://forum.ionicframework.com/u/peterpan666)\
**Post date:** [May 22, 2018, 5:46pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/19 "2018-05-22T17:46:44Z")

</div>

Had the same issue, answered on this issue [https://github.com/ionic-team/ionic/issues/8561#issuecomment-391079689](https://github.com/ionic-team/ionic/issues/8561#issuecomment-391079689)

---

<div class="post-metadata">

**Author:** ![dx1](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@dx1](https://forum.ionicframework.com/u/dx1)\
**Post date:** [September 26, 2018, 6:22pm UTC](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985/20 "2018-09-26T18:22:02Z")

</div>

I could workaround this using the compareWith attribute.

in the template :

```auto
[compareWith]="compareFn.bind(this)"

```

and on ts :

```auto
compareFn(c1: any, c2: any): boolean {
        return c1 && c2 ? c1.id === c2.id : c1 === c2;
    }

```

hope it helps

[Next page](https://forum.ionicframework.com/t/ion-selected-doesnt-show-the-selected-option/77985.md?page=2)
