简体   繁体   中英

How to implement dropdown select box using alert prompt in ionic2 & typescript?

The code example for alertprompt is mentioned below:


let prompt = this.alertCtrl.create({
            title: 'Bid on this delivery',
            inputs: [
                {
                    name: 'amount',
                    placeholder: '£ 0.0'
                },
            ],
            select: [
                {
                    ???????????
                },
            ],
            select: [
                {
                    name: 'expiry',
                    options: {
                        option: 'Nerver',
                        option: '24 hours'
                    },
                    placeholder: ''
                },
            ],
            buttons: [
                {
                    text: 'Cancel',
                    handler: data => {
                        console.log('Cancel clicked');
                    }
                },
                {
                    text: 'Save',
                    handler: data => {
                        console.log('Saved clicked');
                    }
                }
            ]
        });
        prompt.present();

    }

For input the typescript code is:

[
    {
        name: 'amount',
        placeholder: '£ 0.0'
    }
]

How to implement dropdown select box?

     select: [
        ??????????????????????????
     ]

That depends on what you want to present in the dropdown. I would stick with https://github.com/pleerock/ng2-dropdown .

This code is taken from their documentation with some customizations tailored to your problem.

<div class="dropdown" dropdown [dropdownToggle]="false" (onOpen)="doSomeActionOnOpen()" (onClose)="doSomeActionOnClose()">
<button class="btn btn-primary" dropdown-open>My Heroes</button>
<ul class="dropdown-menu">
    <li *ngFor="let val of values"><a>{{val.placeholder}}</a></li>
</ul>

In the component that host this HTML you will need to place the values member. Assuming that AmountValue is your object = { name: 'amount', placeholder: '£ 0.0' }

@Component({....})
export class MyComponent {
    public values: Array<AmountValue>();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM