0

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");
        }   

}

}
1
  • 2
    You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase Database console. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. Commented Sep 28, 2016 at 23:54

1 Answer 1

1

I think you're looking for this:

var user = firebase.auth().currentUser;
this.addsnotes = af.database.list('users/'+user.uid+'/addnote');
Sign up to request clarification or add additional context in comments.

3 Comments

thanks! only one lingering issue (hopefully). when called inside the constructor, I get a uid of null error. What should I be setting uid to? Currently I get a bunch of dots (indicating that the li element is indeed present). However, I get no text, and I get a uid error.
I added my full ts code to the question. The HTML remains unchanged.
I altered the HTML from {{addsnote?addnote}} to {{addnote}} and now my list shows [object Object]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.