获取数据后在html上显示AngularFireList

时间:2017-10-22 17:51:50

标签: angular firebase ionic-framework angularfire2

我试图显示AngularFireList<>在html上。

test=$( echo "$holidaysXML" | egrep "[0-9]{4}-[0-9]{2}-[0-9]{2}|>RP<" )
echo "$test"

我可以使用此代码获取数据,但我想我不能使它等于profileData,所以我无法在屏幕上显示它。

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {AngularFireAuth} from 'angularfire2/auth';
import {AngularFireDatabase,AngularFireList} from 'angularfire2/database';



@Component({
  selector: 'page-profile',
  templateUrl: 'profile.html'
})

export class ProfilePage {
  profileData: AngularFireList<any>


  constructor(private fire:AngularFireAuth,private db :AngularFireDatabase,public navCtrl: NavController) {

    this.fire.authState.subscribe(auth => {
    // subscribe to the observable
    this.profileData = this.db.list<profileData>(`profile/${auth.uid}`).valueChanges().subscribe(p =>{

console.log(p);

    });


  });



  }

}

3 个答案:

答案 0 :(得分:0)

无需订阅valueChanges()。 见angularfire2 docs

答案 1 :(得分:0)

你的代码应该是,

this.profileData = this.db.list<profileData>(`profile/${auth.uid}`).valueChanges();

答案 2 :(得分:0)

我遇到了同样的问题,为了遇到此类错误的未来用户的利益,这应该可行

this.profileDataRef = this.db.list(`profile/${auth.uid}`);      
    this.profileData = this.profileDataRef.valueChanges();    

HTML模板

<ul *ngFor="let profile of profileData | async">
       <li> {{ profile.username}}:{{ profile.msgnumber}} </li>
    </ul>