【问题标题】:Error with Ionic 3, Firebase and angularfire2Ionic 3、Firebase 和 angularfire2 出错
【发布时间】:2018-07-22 02:37:06
【问题描述】:

我收到以下错误消息:

ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

当我尝试列出我的 firebase 数据库中的数据时,我不知道为什么。查看我的代码,我的相关部门

"@ionic-native/core": "~4.9.2",
...
"angularfire2": "^5.0.0-rc.11",
"firebase": "^5.2.0",
"ionic-angular": "3.9.2",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",

我的服务

import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Item } from './../../models/item/item.model';

@Injectable()
export class ShoppingListService {

  private shoppingListRef;
  constructor(private db: AngularFireDatabase) {
    this.shoppingListRef = this.db.list<Item>('shopping-list');
  }

  getShoppingList() {
    return this.shoppingListRef;
  }

}

我的组件

...
export class HomePage implements OnInit {

  shoppingList$: Observable<Item[]>

  constructor(
    public navCtrl: NavController,
    private shopping: ShoppingListService
  ) {}

  ngOnInit() {
    this.shoppingList$ = this.shopping
    .getShoppingList()
    .snapshotChanges()
    .subscribe(changes => {
      return changes.map(change => {
        let retorno = {
          key: change.payload.key,
          ...change.payload.val()
        };
        return retorno;
      });
    });
  }
...

最后是我的模板

<ion-item *ngFor="let item of shoppingList$ | async">
   {{item.name}}
</ion-item>

如果我删除 async 管道,我也会遇到同样的错误。我已经尝试过这个问题但没有成功: Angular 4: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

知道我做错了什么吗?提前致谢。

【问题讨论】:

    标签: firebase ionic3 angularfire2


    【解决方案1】:

    这是从 angularfire2 中检索数据的旧方法,现在我让它与这个一起工作:

    在我的组件中:

    ...
    export class HomePage implements OnInit {
    
      shoppingList$: Observable<Item[]>
    
      constructor(
        public navCtrl: NavController,
        private shopping: ShoppingListService
      ) {}
    
      ngOnInit() {
        this.shoppingList$ = this.shopping
        .getShoppingList()
        .valueChanges();
      }
    ...
    

    一切正常。

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 1970-01-01
      • 2018-07-06
      • 2018-02-19
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      相关资源
      最近更新 更多