Stav Geffen
Stav Geffen

Reputation: 308

quering for objects with angularFireCollection?

I used the implicit method for retrieving data objects:

setData = function(segment){
  var url = 'https://myFireBase.firebaseio.com/';
  var rawData = angularFire(url+segment,$rootScope,'data',{});
  rawData.then(function(data){
    // sorting and adjusting data, and then broadcasting and/or assinging
  }
}

This code is located inside a service that gets called from different locations, by development stages it'll probably be around 100 - 150 so I got out of the controllers and into a service, but now firebase data-binding would obviously over-write the different segments so I turned back to explicit methid, to have the different firebases only sending the data to site instead of data-binding and over-writing each other:

var rawData = angularFireCollection(url+segment);

And right there I discovered why I chose the implicit in the first place: There's an argument for the typeof, i could tell firebase if I'm calling a string, an array, an object etc. I even looked at the angularfire.js and saw that if the argument is not given, if falls back to identifying it as an array by default.

Now, I'm definitely going to move to the explicit method (that is, if no salvation comes with angular2.0), and reconstructing my firebase jsons to fit the array-only policy is not that big of a deal, but surely there's an option to explicitly call objects, or am I missing something?

Upvotes: 0

Views: 1671

Answers (1)

Anant
Anant

Reputation: 7428

I'm not totally clear on what the question is - with angularFireCollection, you can certainly retrieve objects just fine. For example, in the bundled chat app (https://github.com/firebase/angularFire/blob/gh-pages/examples/chat/app.js#L5):

$scope.messages = angularFireCollection(new Firebase(url).limit(50));

Each message is stored as an object, with its own unique key as generated by push().

I'm also curious about what problems you found while using the implicit method as your app grew. We're really looking to address problems like these for the next iteration of angularFire!

Upvotes: 1

Related Questions