arrays - For loop in an $firebaseArray -
i found similar topics, of them outdated because i'm using angularfire 1.1.1.
i had angularjs app creating markers on google map. data stored in external json files , worked fine when turned arrays. when put data firebase database stopped working. ng directives data works fine, when accessing array data data in js code not work.
app.controller('mapctrl', ['$scope', '$firebasearray', function($scope, $firebasearray){ var ref = new firebase("https://radiant-inferno-6439.firebaseio.com/tracks"); var syncobject = $firebasearray(ref); ...
with old offline json version logging syncobject looked this:
[object, object, object] 0: object 1: object 2: object length: 3 __proto__: array[0]
but looks this:
[] 0: object 1: object 2: object $$added: () { [native code] } $$error: () { [native code] } $$getkey: () { [native code] } $$moved: () { [native code] } $$notify: () { [native code] } $$process: () { [native code] } $$removed: () { [native code] } $$updated: () { [native code] } $add: () { [native code] } $destroy: () { [native code] } $getrecord: () { [native code] } $indexfor: () { [native code] } $keyat: () { [native code] } $loaded: () { [native code] } $ref: () { [native code] } $remove: () { [native code] } $save: () { [native code] } $watch: () { [native code] } length: 3 __proto__: array[0]
why that? when print length of array says 0. tried $loaded function not affect.
syncobject.$loaded().then(function(syncobject) { console.log(syncobject.length); });
neither can access properties of array, impossible loop through it.
looks $loaded() method isn't working. added 2 second timeout between loading data , doing else, started work.
Comments
Post a Comment