firebase - AngularFire Accessing child element methods -



firebase - AngularFire Accessing child element methods -

i'm looking way methods of kid element instead of loading element separately.

let's have post model , each post has comments. how post model:

var post = $firebase(new firebase(firebase_url + "/posts/" + post_name)).$asobject();

each post has comments can access comments using:

post.$loaded(function () { var comments = post.comments; }

now how force new element comments without having load model separately firebase? should able next doesn't work:

comments.$add({text: "hi, there"});

is there proper way firebase methods of kid element without having go server , comments?

firebase load info server once. after javascript code can build many refs on need, without downloading info again.

but post.comments.$asarray() not work, since post plain javascript object (and not $firebase sync anymore).

instead try:

var ref = new firebase(firebase_url + "/posts/" + post_name); var post = $firebase(ref).$asobject(); var comments = $firebase(ref.child("comments")).$asarray(); consider alternate info structure

but may want reconsider info structure. though firebase hierarchical info store, recommend against building nested hierarchies. see avoid building nests on https://www.firebase.com/docs/web/guide/structuring-data.html

because can nest info 32 levels deep, it's tempting think should default structure. however, when fetch info node in firebase, retrieve of kid nodes. therefore, in practice, it's best maintain things flat possible, 1 construction sql tables.

so in case lead having 2 top-level elements posts , comments.

root posts post1 post2 comments post1 post1comment1 post1comment2

and can load post , comments with:

var root= new firebase(firebase_url); var post = $firebase(root.child("posts").child(post_name)).$asobject(); var comments = $firebase(root.child("comments").child(post_name)).$asarray();

firebase angularfire

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -