I am looking to access data across multiple components and have implemented a service to retrieve the necessary data. However, I am encountering an issue when attempting to observe this data. Here is my current code:
@Injectable()
export class NotificationsService {
constructor(private af: AngularFireDatabase) {}
public retrieveNotifications(): Observable<NotificationObj[]> {
return this.af.database.ref(refs.NOTIFICATIONS).on('value', snap => {
const data = snap.val();
return Object.keys(data).map(key => {
return new NotificationObj(key, data[key]);
});
})
}
}
Upon running this code, I receive the following error message:
TS2322: Type '(a: DataSnapshot, b?: string) => any' is not assignable to type 'Observable<NotificationObj[]>'. Property '_isScalar' is missing in type '(a: DataSnapshot, b?: string) => any'.
I am seeking guidance on how to modify my method in order to handle data parsing within the service itself while still being able to listen for changes from components.