Promise
on a given service. My code looks like this:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from '@angular/fire/database';
@Injectable({ providedIn: 'root' })
export class UserService {
readonly baseUrl: string = 'user';
constructor(
private afDb: AngularFireDatabase
) { }
object(id: string) {
return this.afDb
.object('${this.baseUrl}/{${id}}')
.snapshotChanges()
.toPromise()
}
}
The problem is that I can not capture Promise
by using the userService.object
function inside the components. I'm doing this:
@Component({ selector: 'login', templateUrl: './login.html' })
export class Login {
uid: 'teste';
constructor(
public userService: UserService
) { }
login() {
this.userService.object(this.uid)
.then(res => console.log(res))
.catch(err => console.error(err));
}
}
What do I need to get my service to return a promise with the object coming from AngularFireDatabase
?