I am trying to subscribe to an function returning observable object in angular 2 . So when there is any new worker added the main calling function should have the value
// functiion based on firebase DB
getWorkers():Observable<any> {
firebase.database().ref('/workers').on('child_added', (snapshot) => {
return snapshot.val();
});
}
subscriber function
workers: any[];
public ngOnInit() {
this.db.getWorkers().subscribe(workers => this.workers = workers);
}
It is saying the function return type is not Observable and hence throwing error .