ionic3-错误错误:未捕获(承诺):错误:InvalidPipeArgument:' [object Object]'用于管道' AsyncPipe' [英] ionic3 - ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

查看:96
本文介绍了ionic3-错误错误:未捕获(承诺):错误:InvalidPipeArgument:' [object Object]'用于管道' AsyncPipe'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试评论功能已经运行之后,我用ionic3借助firebase做了新闻评论功能,但是当我希望显示在项目错误中的评论出现时.

I did a news comment function by ionic3 with firebase, after testing comment function working already, but when I want the comment showing in my project error coming out.

错误错误:未捕获(承诺):错误:InvalidPipeArgument:管道"AsyncPipe"的"[object Object]"

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

我的项目遵循此教程

html文件

<ion-list>
  <ion-item-group *ngFor="let contact of contactsList | async">
    <ion-item>
      {{contact.$value}}
    </ion-item>
  </ion-item-group>
</ion-list>

    <ion-list>
        <ion-row>
            <ion-col col-6>
                <ion-input type="text" [(ngModel)]="Contact" placeholder="写评论..."></ion-input>
            </ion-col>
            <ion-col>
                <button ion-button color="primary" (click)="addContact()">发布</button>
            </ion-col>      
        </ion-row>
    </ion-list>

ts文件

 import { AngularFireList } from 'angularfire2/database';

 export class NewsDetailPage {
  new: any;
  contactsList:AngularFireList<any>;
  Contact = '';

  constructor(public navCtrl: NavController, public navParams: NavParams,
    private qq: QQSDK, private socialSharing: SocialSharing,
    public firebaseService:FirebaseServiceProvider,public alertCtrl: AlertController
    // private photoViewer: PhotoViewer
  ) {
    this.new = navParams.get('new');
    this.contactsList = this.firebaseService.getContactsList();
  }

  addContact() {
    this.firebaseService.addContact(this.Contact);

    const alert = this.alertCtrl.create({
      title: '评论成功!',
      //subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
      buttons: ['确认']
    });
}

更新:

  getContactsList() {
    return this.angularfiredb.list('/contactsList/');
  }

推荐答案

您需要先将AngularFireList转换为Observable:

You need to first convert the AngularFireList to an Observable :

contactsList: Observable<any[]>;

在构造函数中,您需要对其调用 valueChanges().这是因为AngularFire2版本5.

And in your constructor, you need to call valueChanges() on it. This is since AngularFire2 Version 5.

this.contactsList = this.firebaseService.getContactsList().valueChanges();

这将通过不带 $ key $ value 的可观察对象返回数据.为了以html格式打印,请使用

This will return the data through the observable without $key or $value. In order to print in html,use

  {{contact}}

代替

  {{contact.$value}}

这篇关于ionic3-错误错误:未捕获(承诺):错误:InvalidPipeArgument:&amp;#39; [object Object]&amp;#39;用于管道&amp;#39; AsyncPipe&amp;#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆