I want to subscribe to company-list.component
to getCompanies()
from company.service
. However, I get the following error:
Unable to read subscribe property undefined
This is the code:
company.service.ts
getCompaniesOfUser() { let r; this.userService.getUser().subscribe( res=> r = res, err => console.log(err), ()=>(this.getCompaniesWithSpecificLink()) ) } getCompaniesWithSpecificLink() { if (isAdmin == false) { url = '/user/companies'; } else { url = '/companies'; } return this.getCompanies(url); } getCompanies(url):Observable<Company[]> { return this.http.get(this.host + url) .map((res:Response) => res.json()); }
company-list.component.ts
companies:Company[]; public getTheCompanies() { this._companyService.getCompaniesOfUser() .subscribe(companies => this.companies = companies); <-- the error occurred here }
source share