How to return observable from subscribe

后端 未结 6 1845
萌比男神i
萌比男神i 2020-12-04 15:16

I\'m trying to return an observable when I get a certain value in a subscriber, but I fail miserably.

This is the code:

canActivate(route: Activated         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 15:58

    We can convert the Observable object to promise using toPromise method. so the code can be implemented as followed:

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Promise {
            // get route to be activated
            this.routeToActivate = route.routeConfig.path;
    
            // get user access levels        
            return this._firebase.isUserAdmin
                .map(user => {
                    return (user.access_level === 'admin');
                }).toPromise();
        }
    

提交回复
热议问题