2016-08-06 16 views
6

私はイオン2 ion-slidesを使用していますが、いくつかのインスタンスメソッドを呼びたいと思います。私は(おそらく時代遅れ)の例に見られる次のコードを使用しようとしているイオンスライドのインスタンスを取得する方法

<ion-content padding> 
    <ion-slides (ionDidChange)="onSlideChanged($event)" id="loopSlider"> 
    <ion-slide *ngFor="let slide of slides"> 
    <h1>{{ slide.title }}</h1> 
    </ion-slide> 
</ion-slides> 
</ion-content> 

private gotoSlide(index: number): void { 
    this.sliderComponent = this.app.getComponent('loopSlider'); 
    this.sliderComponent.slider.slideTo(index); 
    } 

しかしthis.app.getComponent('loopSlider');は常にnullを返し、私は次のマークアップを持っています。

コンポーネントインスタンスを取得してそのAPIを使用する方法を知っている人はいますか?

答えて

4

the Ionic documentationごとに、あなたは@ViewChildを使用してこの操作を行うことができます。そのため

import { Component, ViewChild } from '@angular/core'; 
import { Slides } from 'ionic-angular'; 
... 

@Component({ 
    ... 
}) 
class MyPage { 
    @ViewChild('loopSlider') sliderComponent: Slides; 

    ... 
} 
+0

大感謝を!そしてそこにはdoco(私が見逃した)の中にあります。 – peterc

+0

誰もがまだ問題にぶつかっているので、本当に 'Slides'をインポートしてください! – Robert

関連する問題