我正在努力从firebase检索UserAuth数据并将其呈现在列表中。我设法把它放在那里,但我无法取回它。我已经参与了许多不同的教程并测试了很多代码:(
对此问题有任何建议吗?我的代码看起来像这样。这可能完全错了。
HTML:
import { Component, OnInit } from '@angular/core';
import { AlertController, NavController, NavParams } from 'ionic- angular';
import { DataService } from '../../providers/data/data.service';
import { AuthService } from '../../providers/auth/auth.service';
import { User } from 'firebase/app';
import { Appointment } from '../../models/appointments/appointments';
@Component({
selector: 'app-appointment-list',
templateUrl: 'appointment-list.component.html'
})
export class AppointmentListComponent implements OnInit {
userAppointment: Appointment;
ngOnInit(): void {
this.auth.getAuthenticatedUser().subscribe((user: User) => {
this.data.getAppointment(user).subscribe((appointment: Appointment) => {
this.userAppointment = appointment;
});
});
}
constructor(public navCtrl: NavController, public navParams: NavParams, private data: DataService, private auth: AuthService) {
}
}
组件
import { Injectable } from '@angular/core';
import { AngularFireDatabase, FirebaseObjectObservable, FirebaseListObservable } from 'angularfire2/database-deprecated';
import { AngularFireDatabaseModule } from 'angularfire2/database-deprecated';
import { User } from 'firebase/app';
import { Appointment } from '../../models/appointments/appointments';
import "rxjs/add/operator/take";
@Injectable()
export class DataService {
appointmentlist: FirebaseListObservable<Appointment[]>
constructor(private database: AngularFireDatabase) {
}
getAppointment(user: User) {
this.appointmentlist = this.database.list(`/appointments/${user.uid}`, {preserveSnapshot: true });
return this.appointmentlist.take(1);
}
}
提供商/ DataService的
{{1}}
FireBase上的数据结构如下所示: DataStructure on Firebase
我希望有人可以指出我正确的方向。
祝你好运 彼得