Reputation: 15299
I am trying to fetch data from firebase
using angularfire
, but i thrown error as TypeError: $firebaseArray.$loaded is not a function
. how to fix this?
here is my factory module:
(function () {
"use strict";
angular
.module("tcpApp")
.factory("server", ['$resource','$firebaseArray', function ($resource, $firebaseArray) {
var projectsData = new Firebase("https://tcp.firebaseio.com/projects");
$firebaseArray.$loaded(projectsData).then(function (data) {
console.log(data);
})
//return $resource('http://localhost:2403/projects/:id', {id:'@id'});
}]);
})();
Upvotes: 0
Views: 191
Reputation: 599686
That's not how you initialize a $firebaseArray
. Instead:
var projectsData = new Firebase("https://tcp.firebaseio.com/projects");
$firebaseArray(projectData).$loaded(projectsData).then(function (data) {
console.log(data);
})
Please take a moment to follow the AngularFire quickstart and programming guide, as both will save you much time with problems like this.
That documentation will also show the best way for monitoring the loading of data. Instead of $loaded
+console.log
, bind the $firebaseArray
to the scope:
var projectsData = new Firebase("https://tcp.firebaseio.com/projects");
$scope.projects = $firebaseArray(projectData)
And then in your view HTML, show it like this:
<pre>{{ projects | json }}</pre>
In general there is hardly ever a need for $loaded
. It will only trigger once, when the initial contents of the array have loaded. But $firebaseArray
is a synchronized array, that may be updated many times after the initial load and $loaded
will not fire for those subsequent updates.
Upvotes: 3