2017-08-21 5 views
3

では一つのコンポーネント機能を使用することができ、ここで私は2コンポーネントと同様CacadingComponentそしてLoginComponent私はLoginComponentAngular2どのように私は別のコンポーネント

にCacadingComponent機能を消費したくあり

CacadingComponent

export class CascadingComponent { 
    CountryList: Country[]; 
    constructor(private _CacadeService: CascadindService) {  
    } 
    GetCountry() { 
     return this._CacadeService.GetCountryList().subscribe((data) => this.CountryList = data); 
    } 

LoginComponent.ts

ここで私はLoginComponentでGetCountry()関数を呼びたいと思っています

下図のようにあなたは、クラス CascadingComponentのオブジェクトを作成することにより、メソッドにアクセスすることができます
export class LoginComponent{ 
//Here How can I call 
} 
+0

共有機能を持っているしたい場合は、サービスを利用することができ、など また、あなたが使用する可能性がありますコンポーネントのビュー内のコンポーネント –

+0

はい@Dawidでも要件は異なる –

答えて

2
export class LoginComponent implements OnInit{ 
    @ViewChild(CascadingComponent) cascadingComponent: CascadingComponent ; 
    ngOnInit(){ 
    this.cascading.GetCountry();} 
} 
3

export class LoginComponent implements OnInit{ 

     cascadingComponent = new CascadingComponent(); 

     ngOnInit(){ 
     this.cascadingComponent.GetCountry(); 
     } 
} 
関連する問題