I have an angular2 application with a service that makes a HTTP call that has various subscribers (each showing a different piece of info). Once the first call is completed, I need to make a second independent HTTP call, and based on the values retrieved, filter the array obtained from the first call. Its not working, the subscribers of the second HTTP call, doesn't know to wait and i get an empty list since the array of the first call is not yet there
Im attaching the relevant service
constructor(private http: Http) {
this.initializeAlertService();
console.log('Started alerts service');
}
initializeAlertService() {
if (!this.allData$) {
this.allData$ = <BehaviorSubject<Alert[]>> new BehaviorSubject(new Array<Alert>());
this.http.get(this.url)
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw(error || 'Server Error'))
.subscribe(
allData => {
this.allData = allData;
this.allData$.next(allData);
this.initializeAlertSeverities(); -- I want this to fire when the 'allData' is ready
},
error => console.log("Error subscribing to AlertService: " + error)
);
}
}
subscribeToAlertSeverities(): Observable<AlertSeverity[]> {
return this.alertSeverities$.asObservable();
}
then on my component i subscribe to the alertSeverities, yet i get not data....