Skip to content

Commit

Permalink
feat(select): cancel output event
Browse files Browse the repository at this point in the history
Closes #5439
  • Loading branch information
adamdbradley committed Feb 13, 2016
1 parent 5034c1d commit 6a7c97d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
13 changes: 11 additions & 2 deletions ionic/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ export class Select {
@Input() checked: any = false;

/**
* @private
* @output {any} Any expression you want to evaluate when the selection has changed
*/
@Output() change: EventEmitter<any> = new EventEmitter();

/**
* @output {any} Any expression you want to evaluate when the selection was cancelled
*/
@Output() cancel: EventEmitter<any> = new EventEmitter();

constructor(
private _form: Form,
private _elementRef: ElementRef,
Expand Down Expand Up @@ -196,7 +200,12 @@ export class Select {

// make sure their buttons array is removed from the options
// and we create a new array for the alert's two buttons
alertOptions.buttons = [this.cancelText];
alertOptions.buttons = [{
text: this.cancelText,
handler: () => {
this.cancel.emit(null);
}
}];

// if the alertOptions didn't provide an title then use the label's text
if (!alertOptions.title && this._item) {
Expand Down
13 changes: 13 additions & 0 deletions ionic/components/select/test/single-value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {App, Page} from '../../../../../ionic/ionic';
templateUrl: 'main.html'
})
class E2EPage {
musicAlertOpts;
gender: string;

constructor() {
this.musicAlertOpts = {
title: '1994 Music',
Expand All @@ -16,6 +19,14 @@ class E2EPage {
}, 1500);
}

gamingCancel() {
console.log('Gaming Select, Cancel');
}

gamingChange(selectedValue) {
console.log('Gaming Select, Change value:', selectedValue);
}

stpSelect() {
console.log('STP selected')
}
Expand All @@ -30,6 +41,8 @@ class E2EPage {
template: '<ion-nav [root]="root"></ion-nav>'
})
class E2EApp {
root;

constructor() {
this.root = E2EPage;
}
Expand Down
2 changes: 1 addition & 1 deletion ionic/components/select/test/single-value/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ion-item>
<ion-label>Gaming</ion-label>
<ion-select [(ngModel)]="gaming">
<ion-select [(ngModel)]="gaming" (cancel)="gamingCancel()" (change)="gamingChange($event)">
<ion-option value="nes">NES</ion-option>
<ion-option value="n64">Nintendo64</ion-option>
<ion-option value="ps">PlayStation</ion-option>
Expand Down

0 comments on commit 6a7c97d

Please sign in to comment.