Answer the question
In order to leave comments, you need to log in
How to get information from Firebase without subscribe?
I have such a situation that one Observable<User>
is inside the other Observable<Params[]>
, which is why I have to use Observable.subscribe nested in each other.
I need to get as an object one specific user from the database, whose id matches the route parameter.
Can you please tell me how to avoid this situation and get information from Firebase without a subscription? Because in fact, I do not need to subscribe to this user. I just need to get data about it to display on the form. Is this even possible?
If not, then how can nested subscriptions be avoided, because somewhere I came across the opinion that nested subscribes is not very good ...
Working with AngularFire 5
export class UserAddEditComponent implements OnInit {
userForm: FormGroup;
userId: string;
constructor(private route: ActivatedRoute, private usersService: UsersService) { }
ngOnInit() {
this.route.params.subscribe((params: Params) => {
if (params['id']) {
this.userId = params['id'];
this.usersService.getUser(this.userId).subscribe((user) => {
this.initForm(user);
});
} else {
this.initForm();
}
});
}
getUser()
service method UsersService
returnsObservable<User>
getUser (id: string): Observable<User> {
return this.firebase.doc<User>(`users/${id}`).valueChanges();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question