InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

Viewed 39320

Declared in service like this:

public currentDBUserBS$: any;

constructor(private afDb: AngularFireDatabase){}

fetchUser(uid){
  this.afDb.object(`users/${uid}`).valueChanges().subscribe((dUser) => {
    if (dUser) {
      this.currentDBUserBS$ = dUser;
    }
  });
}

Now trying to use in template

template: `<li *ngIf="(authService.currentDBUserBS$ | async)?.role=='admin'"> Something </li>`

The error stack:

ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
    at invalidPipeArgumentError (common.js:4219)
    at AsyncPipe._selectStrategy (common.js:5630)
    at AsyncPipe._subscribe (common.js:5612)
    at AsyncPipe.transform (common.js:5586)
    at Object.View_AppNavigatorComponent_0._co [as updateDirectives] (AppNavigatorComponent.html:40)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:14339)
    at checkAndUpdateView (core.js:13508)
    at callViewAction (core.js:13858)
    at execComponentViewsAction (core.js:13790)
    at checkAndUpdateView (core.js:13514)
3 Answers

You must add .valueChanges(); after subscribing operation. It is required as shown below:

 this.courses$=db.list('/courses').valueChanges();
Related