这里我有2个像CacadingComponent和LoginComponent的组件我想在LoginComponent中使用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()函数
export class LoginComponent{
//Here How can I call
}
答案 0 :(得分:3)
您可以通过制作类CascadingComponent
的对象来访问方法,如下所示:
export class LoginComponent implements OnInit{
cascadingComponent = new CascadingComponent();
ngOnInit(){
this.cascadingComponent.GetCountry();
}
}
答案 1 :(得分:2)
export class LoginComponent implements OnInit{
@ViewChild(CascadingComponent) cascadingComponent: CascadingComponent ;
ngOnInit(){
this.cascading.GetCountry();}
}