Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70446

How to preselect ion-picker items?

$
0
0

@donotsue wrote:

Hi there,

on Ionic 4 I’m trying to preselect items on the <ion-picker> before it shows up.

Following code shows the regular way of creating and showing up the picker (it’s allmost the same way like the AlertController).

import { PickerController } from '@ionic/angular';

      constructor(private pickerCtrl: PickerController) {}

      ...
      const pickerCtrl = await this.pickerCtrl.create({
        ...
        columns: [
            {
              name: 'myColumn',
              options: [
                {
                  text: 'A',
                  value: 'A',
                  selected: false
                },
                {
                  text: 'B',
                  value: 'B',
                  selected: true
                }
              ]
            },
            ...
        ]
        ...
        await pickerCtrl.present();


      });

There you can see, I initialize the columns with the B-item preselected. But when the picker shows up, the A-item got the selected: true and the B-item changed to selected: false. Even setting the selected-properties of the items AFTER creation and shownes of the picker it still does not change the selection. Every time the picker starts with the first column items.

Please … how do I accomplish the preselection of an ion-picker?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70446

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>