我想弄清楚一切都出了问题。我所有的观察对象都返回[object Object]。AngularFire2返回[对象对象]
我sunshine.component.html
<h4>Welcome {{username$}}</h4>
<ul>
<li *ngFor="let addsnote of addsnotes$ | async">{{ addsnote }}</li>
</ul>
我sunshine.component.ts
import { Component, OnInit, Injectable } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
export class ProfileComponent implements OnInit {
private addsnotes$: FirebaseListObservable<string[]>;
private username$: FirebaseObjectObservable<string>;
private profileshow = false;
addForm: FormGroup;
constructor(private af: AngularFire){
this.addForm = new FormGroup({
'addnote': new FormControl()
});
}
ngOnInit(){
let user = firebase.auth().currentUser,
userNamePath = `users/${user.uid}/username`,
notesPath = `users/${user.uid}/addnote`;
this.username$ = this.af.database.object(userNamePath);
this.addsnotes$ = this.af.database.list(notesPath);
}
addSubmit(){this.addsnotes$.push('Billy Dee Williams');}
}
我的火力地堡数据库的某些部分
{
"users" : {
"4twiyaFxVmaESXGWIfW4BwRXh893" : {
"addnote" : {
"-KSmWtpUSFXPCL4O3aKr" : "Do the dishes"
},
"useremail" : "[email protected]",
"username" : "majic"
},
"PYuSE6zyAENdKREZGTHm5VH1DXn1" : {
"addnote" : {
"-KSoZM7sH6X5ahMq7S5y" : "Du the dishes",
"-KSoZMimZzm6ZGQowmuL" : "Du the dishes",
"-KSouEXkc1UkyISGTCHd" : "Du the dishes"
},
"useremail" : "[email protected]",
"username" : "asdasd"
}
}
}
我的网页的屏幕截图(为清楚起见)
编辑我已经包括了我正在进行的项目的回购这里,从而为您提供一切尽可能多的信息作为可能。希望它是有用的。
https://github.com/emjayweb/demo
各文件在SRC /应用/简档/ profile.component。由于这完全是WIP,请不要为它的后勤问题感到担忧(警卫路由,验证等)。
这种方式的作用是在主页上输入一些虚拟数据创建账户,然后点击导航上的配置文件链接。您可能必须先刷新页面。当您点击配置文件路线中的按钮时,您输入'Billy Dee Williams'到您的addnote
阵列,并且视图应该反映这一点。
你需要一个'| async',因为FirebaseObjectObservable也是一个需要解包的异步可见性:'
欢迎{{username $ | async}}
'。我们正在努力通过一些方法使指令更简单。 – Kato感谢您的信息。我想知道如何格式与对象的异步。这仍然不能解决我的'[对象对象]'问题。我仍然不明白为什么会发生这种情况。 – abrahamlinkedin
试着将它输送到json然后看看你有什么。 {{用户名|异步| json}} – Kato