# Ionic 4 ion-select pre select value

**URL:** <https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025>\
**Category:** Ionic Framework\
**Created:** [February 21, 2019, 4:15am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025 "2019-02-21T04:15:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![javasol](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@javasol](https://forum.ionicframework.com/u/javasol)\
**Post date:** [February 21, 2019, 4:15am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/1 "2019-02-21T04:15:39Z")

</div>

I have an ion-select that the selected value is coming from a sqlite database, meaning the value for [(ngModel)] is being populated async. In ionic v3 this would still work and would select the correct ion-option, with v4 it doesn’t. Is there any way to get this to work?

```auto
 <ion-select [(ngModel)]="selectedCodeValue" name="selectCode" multiple="false"
        (ionChange)="codeSelected()" required >
        <ion-select-option *ngFor="let code of availableCodes" value="{{code.id}}">
          {{code.id}} - {{code.description}}
        </ion-select-option>
  </ion-select>

```

In the above snippet the “selectedCodeValue” gets populated async from sqlite db.

---

<div class="post-metadata">

**Author:** ![javasol](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@javasol](https://forum.ionicframework.com/u/javasol)\
**Post date:** [February 22, 2019, 1:21am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/2 "2019-02-22T01:21:03Z")

</div>

I just double checked and it has nothing to do with async data load or not. Even when I used a hard coded variable it still didn’t show the selected value until I clicked on the select, that’s when the selected value is automatically selected.

As a workaround I put the value in the ion-select placeholder attribute. That worked but it feels like a hack

```auto
<ion-select [(ngModel)]="selectedCodeValue" name="selectCode" multiple="false" [placeholder]="selectedCodeValue ? selectedCodeValue : 'Tap to select..'"
        (ionChange)="codeSelected()" required >
        <ion-select-option *ngFor="let code of availableCodes" value="{{code.id}}">
          {{code.id}} - {{code.description}}
        </ion-select-option>
  </ion-select>

```

---

<div class="post-metadata">

**Author:** ![javasol](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@javasol](https://forum.ionicframework.com/u/javasol)\
**Post date:** [February 22, 2019, 2:39am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/3 "2019-02-22T02:39:31Z")

</div>

Ok I finally got it to work. I was missing the selectedText attribute. Now it works as expected

```auto
<ion-select [(ngModel)]="selectedCodeValue" name="selectCode" 
  multiple="false" placeholder="Tap to select.." [selectedText]="selectedCodeValue"
  (ionChange)="codeSelected()" required >
        <ion-select-option *ngFor="let code of availableCodes" value="{{code.id}}">
          {{code.id}} - {{code.description}}
        </ion-select-option>
  </ion-select>

```

---

<div class="post-metadata">

**Author:** ![javasol](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@javasol](https://forum.ionicframework.com/u/javasol)\
**Post date:** [February 22, 2019, 3:06am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/4 "2019-02-22T03:06:24Z")

</div>

1 more thing that I noticed, putting it here if anyone runs into this issue.

When it’s a multiselect (multiple=true) and you set [selectedText]=“selectedCodeValue” it will display 1 long string instead of comma separated string. The way I avoid it is as follows

```auto
<ion-select [(ngModel)]="selectedCodeValue" name="selectCode" 
  multiple="true" placeholder="Tap to select.."
  [selectedText]="selectedCodeValue ? selectedCodeValue.toString() : selectedCodeValue"
  (ionChange)="codeSelected()" required >
        <ion-select-option *ngFor="let code of availableCodes" value="{{code.id}}">
          {{code.id}} - {{code.description}}
        </ion-select-option>
  </ion-select>

```

---

<div class="post-metadata">

**Author:** ![hardydex](https://avatars.discourse-cdn.com/v4/letter/h/eada6e/32.png) [@hardydex](https://forum.ionicframework.com/u/hardydex)\
**Post date:** [March 11, 2019, 2:16am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/5 "2019-03-11T02:16:30Z")

</div>

set the value property of the ion-select to accomplish the ion-select-option being selected.

\<ion-select [(ngModel)]=“selectedCodeValue” name=“selectCode” multiple=“true” placeholder=“Tap to select…” [value]=“selectedCodeValue” (ionChange)=“codeSelected()” required\>  
\<ion-select-option \*ngFor=“let code of availableCodes” value="{{code.id}}"\>  
{{code.id}} - {{code.description}}

---

<div class="post-metadata">

**Author:** ![dismipaul](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@dismipaul](https://forum.ionicframework.com/u/dismipaul)\
**Post date:** [March 13, 2019, 9:26am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/7 "2019-03-13T09:26:38Z")

</div>

Hope this helps  
In html file:

```auto

<ion-content padding>
  Select one
    <ion-select name="category" [selectedText]="selectcategory" [(ngModel)]="selectcategory" (ionChange)="codeSelected()" >
        <ion-select-option value="1" >Category 1</ion-select-option>
        <ion-select-option value="2">Category 2</ion-select-option>
        <ion-select-option value="3">Category 3</ion-select-option>
        </ion-select>
        
</ion-content>

```

In ts file

```auto

export class TestcodePage implements OnInit {
  selectcategory:any;
  selectcategory1:any;
  constructor() {
    this.selectcategory="Category 2";
    //this.selectcategory=1;
  }

  ngOnInit() {
  }
  codeSelected(){
    switch(this.selectcategory)
    {
      case "1": 
      this.selectcategory="Category 1";
      break;
      case "2": 
      this.selectcategory="Category 2";
      break;
      case "3": 
      this.selectcategory="Category 3";
      break;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ThinkIn](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@ThinkIn](https://forum.ionicframework.com/u/ThinkIn)\
**Post date:** [August 13, 2019, 5:46am UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/8 "2019-08-13T05:46:00Z")

</div>

Tks brother i spended hours looking how to work arround with it. You rock…

---

<div class="post-metadata">

**Author:** ![olsikarapici](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@olsikarapici](https://forum.ionicframework.com/u/olsikarapici)\
**Post date:** [October 1, 2019, 2:28pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/9 "2019-10-01T14:28:23Z")

</div>

Thanks man, it works.  
The [selectedTex] seems to do the trick.  
Thank you for saving me a lot of time.

---

<div class="post-metadata">

**Author:** ![selvakumar](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@selvakumar](https://forum.ionicframework.com/u/selvakumar)\
**Post date:** [February 29, 2020, 2:42pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/10 "2020-02-29T14:42:20Z")

</div>

Try this method it works.  
Nationality

```
              <ion-select formControlName="nationality" [value]="nationalid" interface="action-sheet" (ionChange)="changeNationality()">

                <ion-select-option *ngFor="let nationality of nationalityList" [value]="nationality.id">

                  {{nationality.nationality}}</ion-select-option>

              </ion-select>
```

---

<div class="post-metadata">

**Author:** ![sabahang](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sabahang/32/129236_2.png) [@sabahang](https://forum.ionicframework.com/u/sabahang)\
**Post date:** [April 16, 2020, 4:58pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/11 "2020-04-16T16:58:54Z")

</div>

hey @javasol thanks for posting your solution. this works for showing the string but when I open the action sheet it actually doesn’t show the selected values as selected (I’m having a multiselect option and I expect to see that when I open it the fetched values are already selected)  
PS: this used to work when I could use the select property of the IonSelectOption but in Ionic 5 they removed support for that property)

---

<div class="post-metadata">

**Author:** ![farfalla](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@farfalla](https://forum.ionicframework.com/u/farfalla)\
**Post date:** [March 11, 2021, 2:31pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/12 "2021-03-11T14:31:01Z")

</div>

I am working with Ionic Vue but I think I have a similar problem.

is your `selectedCodeValue` an Object of the selected element(s) or a string of the selectedText or both? somehow I still have problems setting the value and I don’t understand how your model and selectedText can be the same. and I have the same problem as @sabahang

---

<div class="post-metadata">

**Author:** ![twestrick](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/twestrick/32/136131_2.png) [@twestrick](https://forum.ionicframework.com/u/twestrick)\
**Post date:** [March 11, 2021, 2:34pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/13 "2021-03-11T14:34:19Z")

</div>

Check out my post over [here](https://forum.ionicframework.com/t/setting-ion-segment-value-dynamically-reactively/206023). Using `v-model` in Vue fixed the issue in Ionic for selecting the tab.

---

<div class="post-metadata">

**Author:** ![twestrick](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/twestrick/32/136131_2.png) [@twestrick](https://forum.ionicframework.com/u/twestrick)\
**Post date:** [March 11, 2021, 2:39pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/14 "2021-03-11T14:39:03Z")

</div>

Oh, lol, sorry. I totally read this wrong. You are working with `ion-select` and not `ion-segment`. But maybe using `v-model` will fix the issue here too?

---

<div class="post-metadata">

**Author:** ![farfalla](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@farfalla](https://forum.ionicframework.com/u/farfalla)\
**Post date:** [March 11, 2021, 2:46pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/15 "2021-03-11T14:46:34Z")

</div>

thank you @twestrick for trying to help. yes in fact I am using v-model. the `ion-select-option`s are all listed correctly and I can select them but I can’t get an initial value (a first pre selection) inside the `ion-select`. any trial with `:value`, `:selected-text` or other didn’t work

---

<div class="post-metadata">

**Author:** ![javasol](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@javasol](https://forum.ionicframework.com/u/javasol)\
**Post date:** [March 11, 2021, 5:03pm UTC](https://forum.ionicframework.com/t/ionic-4-ion-select-pre-select-value/157025/16 "2021-03-11T17:03:40Z")

</div>

Hi. Unfortunately I haven’t touched Ionic in almost 2 years. Can’t really help you but maybe someone else here can
