如何将Observable分配给FirebaseObjectObservable?
目前我收到以下错误
Type '{}' is not assignable to type 'FirebaseObjectObservable<UserProfile[]>'.
Property '_ref' is missing in type '{}'.
方法getUserProfile
getUserProfile() {
const getUser = new Subject();
this.getUser().subscribe(
authResp => {
console.log('response received from getUser():', authResp);
const data = this.af.database.object(`users/${authResp}`);
getUser.next(data);
getUser.complete();
},
err => {
getUser.error(err);
getUser.complete();
}
)
return getUser.asObservable();
}
组件
export class HomeComponent implements OnInit, OnDestroy {
private sub: Subscription;
theUserProfile: FirebaseObjectObservable<UserProfile[]>;
constructor(private authService:AuthService, private af: AngularFire, private auth: FirebaseAuth) {}
ngOnInit() {
this.sub = this.authService.getUserProfile().subscribe( data => {
console.log('this is data:', data);
this.theUserProfile = data;
})
}
ngOnDestroy() {
this.sub.unsubscribe();
}
}
问题是:如何将数据输出分配给this.theUserProfile? console.log('这是数据:',数据);返回this is data: FirebaseObjectObservable {_isScalar: false, _ref: U}
答案 0 :(得分:0)
感谢Fabio的建议,我能够回答我自己的问题。
需要在我的组件中更改以下内容。
export class HomeComponent implements OnInit, OnDestroy {
private sub: Subscription;
theUserProfile;
constructor(private authService:AuthService, private af: AngularFire, private auth: FirebaseAuth) {}
ngOnInit() {
this.sub = this.authService.getUserProfile().subscribe( data => {
console.log('this is data:', data);
this.theUserProfile = <FirebaseObjectObservable<UserProfile[]>>data;
})