Within my service method that returns an Observable, I am attempting to notify the component using a Subject once an action is completed.
completed: Subject<boolean>
constructor(private http: Http) {
}
loadItems(): Observable<FrontItemDto[]> {
return this.http.get(`${ServiceSettings.ApiUrl}/front`)
.map(res => {
res.json();
if (res.json()) {
this.completed.next(true);
}
})
.catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}
This code snippet demonstrates how the component is set up to listen for updates from the Subject:
ngOnInit(): void {
this.getItems();
this.sub = this.dataService.completed.subscribe(completed => {
if (completed) {
this.show = false;
}
});
}
Despite following these steps, an error message informs me that the Subject (completed) is undefined. Where might I be going wrong?