Currently, I am utilizing Local Storage in an Angular 5 Service by referencing https://github.com/cyrilletuzi/angular-async-local-storage. My goal is to retrieve data from storage initially. In case the value is not present, I intend to fetch data from firebase. However, when I try to check for the existence of data, the database request becomes inaccessible from the service, leading to the error
TypeError: Cannot read property 'subscribe' of undefined
.
PS: In this scenario, the value "user" is definitely not present.
Here's my attempted solution:
getDbFromUser(uid) {
this.localStorage.getItem('user').subscribe((data) => {
if (data) {
console.log(data);
} else {
console.log('Nothing found');
// Load data from Firebase
this.dataObjRef = this.afDatabase.object(`data/users/${uid}`);
this.data = this.dataObjRef.valueChanges();
return this.data;
}
}, () => {
})
}