Ionic and Firebase - InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

后端 未结 1 1972
感情败类
感情败类 2020-12-19 04:24

I am having issue getting a basic CRUD to-do list app using Ionic 3 and Firebase to work.

The error message I am stuck on is:

Uncaught (in promise): Err

相关标签:
1条回答
  • 2020-12-19 04:57

    I think you are using the new angularfire2 version which is version 5 in this case you should be doing the following:

    import { Component } from '@angular/core';
    import { AngularFireDatabase } from 'angularfire2/database';
    import { Observable } from 'rxjs/Observable';
    
    @Component({
      selector: 'page-shopping-list',
      templateUrl: 'shopping-list.html',
    })
    export class ShoppingListPage {
     shoppingListRef$: Observable<any[]>;
      constructor(database: AngularFireDatabase) {
        this.shoppingListRef$ = this.database.list('shopping-list').valueChanges();;
      }
    }
    

    as starting from version 5 database.list no longer returns an observable so you can't subscribe to it in the template using the async pipe. this is why you should chain the valueChanges() method which returns an Observable in this case.

    0 讨论(0)
提交回复
热议问题