【问题标题】:invalidpipeargument: '[object object']: error showinginvalidpipeargument:'[object object']:错误显示
【发布时间】:2018-04-13 17:05:47
【问题描述】:

所以我对 Ionic 和 Firebase 比较陌生,我正在尝试显示 Firebase 中已经存在的用户数据。 这是我得到的错误:

invalidpipeargument: '[object object']: error showing.

在查看了与我类似的其他问题后,我确实知道问题所在。似乎我无法分配异步函数,因为database.object 不返回可观察值。所以我尝试添加.valueChanges(); 使其成为可观察的,但我相信这与angularfireobject 冲突,因为它已经分配给变量profile.data,所以这不起作用。

我也试过这个:

// get (): AngularFireObject<any[]>{
        //return this.afDatabase.list`/profile/${data.uid}`;
        //}

如果您指出我正确的方向,那就太好了。 这是我的代码:

.ts 文件

import { Component } from '@angular/core';
import { NavController, ToastController } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, AngularFireObject} from 'angularfire2/database';
import { Profile } from '../../model/profile';
import { DEFAULT_INTERPOLATION_CONFIG } from '@angular/compiler';

@Component({
  selector: 'page-about',
  templateUrl: 'about.html'
})
export class AboutPage {

  profileData: AngularFireObject<Profile>
    // get (): AngularFireObject<any[]>{
    //return this.afDatabase.list`/profile/${data.uid}`;
    //}

  constructor(private afAuth:AngularFireAuth, private afDatabase: AngularFireDatabase, 
    public navCtrl: NavController, private toast: ToastController) {

  }
  ionViewDidLoad() {
   this.afAuth.authState.take(1).subscribe(data =>{

    if (data && data.email && data.uid){
      this.toast.create({
        message: `Welcome to MatchMyFighter ${data.email}`,
        duration: 3000,
      }).present();

     // this.profileData = this.afDatabase.object(`profile/${data.uid}`)
     this.profileData = this.afDatabase.object(`/profile/${data.uid}`).valueChanges();;
    }

    else{
      this.toast.create({
        message:`could not autenticate`,
        duration:3000
      }).present;
    }
   })
  }



}

.html

<p>
    Username: {{(profileData | async)?.username}}
  </p>

【问题讨论】:

    标签: firebase firebase-realtime-database ionic3 angularfire2


    【解决方案1】:

    valueChanges() 的调用将AngularFireObject&lt;Profile&gt; 转换为可观察对象。 您必须将类型更改为Observable&lt;Profile&gt;,如下所示:

    profileData: Observable<Profile>;
    
    constructor(private db: AngularFireDatabase) { } // other stuff emitted ...
    
    ionViewDidLoad() {
        // ...
        this.profileData = this.db.object<Profile>(`/profile/${data.uid}`).valueChanges();
        // ...
    }
    

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      相关资源
      最近更新 更多