mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
refactor(segment): changed segment event emitter type to SegmentButton and update the change to emit value
Fixed tests to reflect this. References #819
This commit is contained in:
@ -55,7 +55,7 @@ import {isDefined} from '../../util/util';
|
|||||||
})
|
})
|
||||||
export class SegmentButton {
|
export class SegmentButton {
|
||||||
@Input() value: string;
|
@Input() value: string;
|
||||||
@Output() select: EventEmitter<any> = new EventEmitter();
|
@Output() select: EventEmitter<SegmentButton> = new EventEmitter();
|
||||||
|
|
||||||
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
|
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
|
||||||
|
|
||||||
@ -131,8 +131,8 @@ export class SegmentButton {
|
|||||||
selector: 'ion-segment'
|
selector: 'ion-segment'
|
||||||
})
|
})
|
||||||
export class Segment {
|
export class Segment {
|
||||||
@Output() change: EventEmitter<any> = new EventEmitter();
|
|
||||||
@ContentChildren(SegmentButton) _buttons;
|
@ContentChildren(SegmentButton) _buttons;
|
||||||
|
@Output() change: EventEmitter<SegmentButton> = new EventEmitter();
|
||||||
value: any;
|
value: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -169,7 +169,7 @@ export class Segment {
|
|||||||
button.select.subscribe((selectedButton) => {
|
button.select.subscribe((selectedButton) => {
|
||||||
this.writeValue(selectedButton.value);
|
this.writeValue(selectedButton.value);
|
||||||
this.onChange(selectedButton.value);
|
this.onChange(selectedButton.value);
|
||||||
this.change.emit(selectedButton.value);
|
this.change.emit(selectedButton);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isDefined(this.value)) {
|
if (isDefined(this.value)) {
|
||||||
|
@ -20,12 +20,12 @@ class MyApp {
|
|||||||
this.appType = 'free';
|
this.appType = 'free';
|
||||||
}
|
}
|
||||||
|
|
||||||
onSegmentChanged(value) {
|
onSegmentChanged(segmentButton) {
|
||||||
console.log("Segment changed to", value);
|
console.log("Segment changed to", segmentButton.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSegmentClicked(value) {
|
onSegmentSelected(segmentButton) {
|
||||||
console.log("Segment clicked", value);
|
console.log("Segment selected", segmentButton.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
doSubmit(event) {
|
doSubmit(event) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<ion-toolbar>
|
<ion-toolbar>
|
||||||
<ion-segment id="segment" [(ngModel)]="relationship" (change)="onSegmentChanged($event)">
|
<ion-segment id="segment" [(ngModel)]="relationship" (change)="onSegmentChanged($event)">
|
||||||
<ion-segment-button value="friends" (click)="onSegmentClicked('friends')" class="e2eSegmentFriends">
|
<ion-segment-button value="friends" (select)="onSegmentSelected($event)" class="e2eSegmentFriends">
|
||||||
Friends
|
Friends
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="enemies" (click)="onSegmentClicked('enemies')">
|
<ion-segment-button value="enemies" (select)="onSegmentSelected($event)">
|
||||||
Enemies
|
Enemies
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
</ion-segment>
|
</ion-segment>
|
||||||
|
Reference in New Issue
Block a user