0
votes

I've seen that people recommend BehaviorSubject to get its current value with getValue(). However when I use this with my array of objects all that gets console logged is "Observable {_isScalar: false, source: Observable, operator: MapOperator}" with dropdown arrows that lead to everything but the data I need. I feel like I'm missing something but after looking for hours I'm still lost. What am I missing?

Example Code:

defaultData = this.http.get(this.dataUrl);
defaultProducts = new BehaviorSubject<any>(this.defaultData);
products = this.defaultProducts.asObservable();

getData() {
    let test = this.defaultProducts.getValue();
    console.log(test);
    return this.http.get(this.dataUrl);
}
1
Please provide the code where you are getting that log. - Luillyfe

1 Answers

0
votes

I saw this article about using RXJS to pull the values from the observable. I am still trying to figure it out.

 canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean> | boolean {

      return this.auth.user
           .take(1)
           .map(user => !!user)
           .do(loggedIn => {
             if (!loggedIn) {
               console.log('access denied')
               this.router.navigate(['/login']);
             }
         })

  }
}