我似乎无法弄清楚为什么我的db对象被返回为未定义,我在ts文件中使用.subscribe解压缩它,但无法访问其任何值。我想我必须遗漏与使用.child?
有关的事情我称之为填充数据
test() {
this.assessment.first = "test";
this.assessment.second = "test";
this.assessment.third = "test";
this.assessment.education = 1;
this.assessment.civic = 1;
this.assessment.employment = 1;
this.assessment.health = 1;
this.assessment.housing = 1;
this.assessment.social = 1;
this.visionService.createAssessmentItem(this.assessment)
console.log(this.assessment);
}
然后在同一个ts文件中
assessment;
constructor(private visionService: VisionService,
public auth: AuthService) { }
ngOnInit() {
//this.assessments = this.visionService.getAssessment();
this.assessment = this.visionService.getAssessment().subscribe(a => {
this.assessment = a
});
console.log(this.auth.currentUser.uid);
console.log(this.assessment);
}
我打印用户ID以确保它们存在且实际上有数据。
我的服务
getAssessment(): FirebaseObjectObservable<any> {
const path = `/assessments/${this.userId}`
console.log(this.userId) // make sure it matches.
return this.db.object(path);
}
并在db
中0yUcmxq0Tig9TW3mCJWwGOo5c8l1
-KqMjDGfbSb5qS2o0MIL
civic: 1
education: 1
employment: 1
first: "test"
health: 1
housing: 1
second: "test"
social: 1
third: "test"
有人可以展示并解释最佳方法吗?老实说,这可能很难,我觉得我在这里缺少一些关键的东西。