2016-06-24 29 views
0

アドバイスが必要、道を見つけることができません。 私はログアウト と機能をappComponentていますappComponentからhomeComponentへの関数を停止する方法。 Angular2

logout() { 
    "HOMECOMPONENT??".clearInterval(this.timer); //it should go to homeComponent and clearInterval 
    this.authenticationService.logout((result) => this.isLogged()); 
} 

私はログアウトを押すと、homeComponent.if'ts可能と呼ばれる他のコンポーネントに間隔をクリアする最初の必要性を?これを行う方法?

+1

あなたが何を意味シェアードサービス – AngJobs

+0

を使用しますか?あなたはexampleとのリンクを送ることができますか? – Serhiy

+1

新しいサービスクラス 'SharedService.ts'を作成し、' start() 'と' clearInterval() '関数を追加してください。 – AngJobs

答えて

1

HomeComponentAppComponentの直接の子であるなら、あなたはViewChildでそれを参照することができます。

@ViewChild(HomeComponent) 
homeComponent: HomeComponent 

stopHomeTimer() { 
    this.homeComponent.stopTimer(); 
} 

http://learnangular2.com/viewChild/

関連する問題