mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
test: fix all tests to remove app.getComponent
This commit is contained in:
@ -1,40 +1,42 @@
|
||||
import {Validators, Control, ControlGroup} from '@angular/common';
|
||||
import {Http} from '@angular/http';
|
||||
import {App, Page, IonicApp, NavController} from '../../../../../src';
|
||||
import {ViewChild} from '@angular/core';
|
||||
import {App, Page, NavController, Slides} from '../../../../../src';
|
||||
|
||||
|
||||
@Page({
|
||||
templateUrl: 'main.html',
|
||||
})
|
||||
class SegmentPage {
|
||||
constructor(app: IonicApp) {
|
||||
this.app = app;
|
||||
@ViewChild('loopSlider') sliderComponent: Slides;
|
||||
|
||||
selectedSegment = "first";
|
||||
slides = [
|
||||
{
|
||||
id: "first",
|
||||
title: "First Slide"
|
||||
},
|
||||
{
|
||||
id: "second",
|
||||
title: "Second Slide"
|
||||
},
|
||||
{
|
||||
id: "third",
|
||||
title: "Third Slide"
|
||||
}
|
||||
];
|
||||
|
||||
constructor() {
|
||||
|
||||
this.selectedSegment = "first";
|
||||
this.slides = [
|
||||
{
|
||||
id: "first",
|
||||
title: "First Slide"
|
||||
},
|
||||
{
|
||||
id: "second",
|
||||
title: "Second Slide"
|
||||
},
|
||||
{
|
||||
id: "third",
|
||||
title: "Third Slide"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
onSegmentChanged(segmentButton) {
|
||||
console.log("Segment changed to", segmentButton.value);
|
||||
|
||||
this.sliderComponent = this.app.getComponent('loopSlider');
|
||||
const selectedIndex = this.slides.findIndex((slide) => {
|
||||
return slide.id === segmentButton.value;
|
||||
});
|
||||
this.sliderComponent.slider.slideTo(selectedIndex);
|
||||
this.sliderComponent.slideTo(selectedIndex);
|
||||
}
|
||||
|
||||
onSlideChanged(slider) {
|
||||
@ -47,11 +49,12 @@ class SegmentPage {
|
||||
|
||||
|
||||
@App({
|
||||
pages: [SegmentPage],
|
||||
template: `<ion-nav [root]="root"></ion-nav>`
|
||||
})
|
||||
class MyApp {
|
||||
root = SegmentPage;
|
||||
|
||||
constructor() {
|
||||
this.root = SegmentPage;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
<ion-content padding>
|
||||
|
||||
<ion-slides (change)="onSlideChanged($event)" id="loopSlider">
|
||||
<ion-slides (change)="onSlideChanged($event)" #loopSlider>
|
||||
<ion-slide *ngFor="let slide of slides">
|
||||
<h1>{{ slide.title }}</h1>
|
||||
</ion-slide>
|
||||
|
Reference in New Issue
Block a user