Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pop out ion-select using different button

How do I pop out the ion-select using different button?

<ion-select [(ngModel)]="choices" multiple="true">
        <ion-option>Appliances</ion-option>
        <ion-option>Automobile</ion-option>
        <ion-option>Cellphones</ion-option>
        <ion-option>Clothing</ion-option>
        <ion-option>Computers</ion-option>
        <ion-option>Electronics</ion-option>
        <ion-option>Toys</ion-option>
</ion-select>
like image 528
Klt Avatar asked Feb 07 '18 04:02

Klt


People also ask

How do you get selected value from ion-select?

We can access the Ionic select by using a standard <ion-select> element. A select component always used with child <ion-select-option> element. If the <ion-select-option> does not have a value attribute, then its text will be used as the value.

How do you use ion-select?

Selects are form controls to select an option, or options, from a set of options, similar to a native <select> element. When a user taps the select, a dialog appears with all of the options in a large, easy to select list. A select should be used with child <ion-select-option> elements.

How do you clear an ion-select option?

If we want to unselect that selected option, we should have a button/icon (trash or cross) like we have in ion-searchbar to unselect the option and leave the ion-select empty.


1 Answers

You can ViewChild with ionic-angular

html

<ion-select [(ngModel)]="choices" multiple="true" #mySelect>
     <ion-option>Appliances</ion-option>
     <ion-option>Automobile</ion-option>
     <ion-option>Cellphones</ion-option>
     <ion-option>Clothing</ion-option>
     <ion-option>Computers</ion-option>
     <ion-option>Electronics</ion-option>
     <ion-option>Toys</ion-option>
</ion-select>

<button ion-button (click)="openSelect()">Open</button>
<button ion-button (click)="closeSelect()">Close</button>

ts

import { Component, ViewChild } from '@angular/core';
import { NavController,Content, Select } from 'ionic-angular';
import { Events } from 'ionic-angular';

@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage 
{    
    @ViewChild('mySelect') selectRef: Select;
    constructor(public navCtrl: NavController,public events: Events) 
    {}

    openSelect()
    {
        this.selectRef.open();
    }

    closeSelect()
    {
        this.selectRef.close();
    }
}
like image 120
Paresh Gami Avatar answered Sep 21 '22 13:09

Paresh Gami