I have a Firebase DB with array data that I would like to retrieve from a user. Specifically, addnote, with info Du the dishes. For reference, I have included an image of my database.
My DB in JSON Format. I have tried cutting down on some of the excess on account of me horsing around:
{
"items" : {
"-KSm_hb4Rw4rudtjxq6x" : {
"addnote" : "Red"
},
"-KSmc45MdhuXIkNkoiN-" : {
"addnote" : "Red"
},
"-KSmc8ZsUDGb23MapKl9" : {
"addnote" : "Red"
}
},
"users" : {
"PYuSE6zyAENdKREZGTHm5VH1DXn1" : {
"addnote" : {
"-KSnELpl7-dkmjlyGl2x" : "Du the dishes",
"-KSnFBaM4VXOyFTjWtaE" : "Du the dishes",
"-KSnFDlC9hND-M3C2pWE" : "Du the dishes"
},
"useremail" : "[email protected]",
"username" : "asdasd"
},
"ag1ZF6Z4cEZ5AsvusiSD9Z1WyUn2" : {
"useremail" : "[email protected]",
"username" : "jaconb"
}
}
}
I would like to know how to re-arrange the code on my constructor so that it receives my addnote items with respect to its user.
constructor(af: AngularFire){
this.addsnotes = af.database.list('users/' + addnote);//should fetch my notes.
}
addSubmit(){
var self = this;
var user = firebase.auth().currentUser;
var getUserInfo = firebase.database().ref('users/' + user.uid);
if (user){getUserInfo.child('addnote').push("Du the dishes");}
}
Below is the HTML I would like to print this out to:
<li *ngFor="let addsnote of addsnotes | async">{{ addnote }}</li>
EDIT: Fixed my code. Changed the li to call {{addnote}} so that now the call works. However, I get an [object Object] on my array.
export class ProfileComponent implements OnInit {
private username: string;
private addsnotes: FirebaseListObservable<any>;
constructor(af: AngularFire){
var user = firebase.auth().currentUser;
this.addsnotes = af.database.list('users/'+user.uid+'/addnote');
}
ngOnInit(){
var self = this;
}
addSubmit(){
var self = this;
var user = firebase.auth().currentUser;
var getUserInfo = firebase.database().ref('users/' + user.uid);
if (user){
getUserInfo.child('addnote').push("Du the dishes");
}
}
}
