Wait for subscription in constructor of a Service
问题 In my service, I want to wait for until local variable baseurl is not initialized before making another http request. Below is my service code: @Injectable() export class CoursesService { baseUrl; constructor(private http: Http) { if(this.baseUrl != undefined){ this.getJSON().subscribe(data => this.baseUrl=data, error => console.log(error) ); } } public getJSON(): Observable<any> { return this.http.get("assets/apiDetails.json") .map((res:any) => res.json()); } getCourses(){ return this.http