Если вы хотите следовать по предметному пути:
//**app component**
//just initializing preload function() when the app runs - but I want to know here if its an error
ngOnInit() {
this.projectsService.preloadAllProjects();
this.projectService.error$.subscribe(error => console.log(error));
}
// == services ==
//preload all projects
error$: Subject<string> = new Subject();
preloadAllProjects(){
this.http.get('/api/project/allprojects').pipe( map( response => response )).subscribe(result => {
this.allProjectsBehavior.next(result);
}, error => this.error$.next(error);
};
или вы можете вернуть Observable из preloadAllProjects
:
//**app component**
//just initializing preload function() when the app runs - but I want to know here if its an error
ngOnInit() {
this.projectsService.preloadAllProjects().subscribe(success => {}, error => console.log(error))
}
// == services ==
//preload all projects
error$: Subject<string> = new Subject();
preloadAllProjects(){
return new Observable(observer => {
this.http.get('/api/project/allprojects').pipe( map( response => response )).subscribe(result => {
this.allProjectsBehavior.next(result);
observer.next(true);
observer.complete();
}, error => observer.error(error);
});
};