I am puzzled as to how to return the data array from the $loaded promise
back to my $scope.

   $scope.snapshot = fbutil.syncArray("snapshot/" + id)
   $scope.events = []
     $scope.snapshot.$loaded().then (entries) ->
       angular.forEach entries, ((entry) ->
         @push entry
         return
       ), $scope.events
     console.log "$scope.events: ", $scope.events

console.log output for my $scope array events will be [] and not contain
the inside the $loaded promise available entries
I mean an ng-repeat would also bind all entries properly why does the thing
not work in this case?
Any help would be greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/7e37c7dc-771f-4dd0-89d3-165e33a26fc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Jacob Wenger at Sep 21, 2014 at 6:15 pm
    Hey Sven,

    The $loaded() method is asynchronous because it needs to fetch data from
    Firebase which takes some time. As a result, if you log $scope.events
    outside of the promise returned by $loaded() it is expected to be []. I'm
    not a CoffeeScript expert, but I think you just need to indent your
    console.log to include it in the $loaded() promise:

       $scope.snapshot = fbutil.syncArray("snapshot/" + id)
       $scope.events = []
         $scope.snapshot.$loaded().then (entries) ->
           angular.forEach entries, ((entry) ->
             @push entry
             return
           ), $scope.events
           *console.log "$scope.events: ", $scope.events*

    Jacob
    On Sat, Sep 20, 2014 at 11:08 PM, Sven Woldt wrote:

    I am puzzled as to how to return the data array from the $loaded promise
    back to my $scope.

    $scope.snapshot = fbutil.syncArray("snapshot/" + id)
    $scope.events = []
    $scope.snapshot.$loaded().then (entries) ->
    angular.forEach entries, ((entry) ->
    @push entry
    return
    ), $scope.events
    console.log "$scope.events: ", $scope.events

    console.log output for my $scope array events will be [] and not contain
    the inside the $loaded promise available entries
    I mean an ng-repeat would also bind all entries properly why does the
    thing not work in this case?
    Any help would be greatly appreciated.

    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/7e37c7dc-771f-4dd0-89d3-165e33a26fc9%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/7e37c7dc-771f-4dd0-89d3-165e33a26fc9%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CAKZX5-63LeNr1qchXiRPaW1jjxRF2OCbA5mcLpMRyGyXRCJbyw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Kato Wulf at Sep 21, 2014 at 6:26 pm
    Also asked here
    <http://stackoverflow.com/questions/25956481/how-to-bind-angularfire-syncarray-loaded-promise-to-scope>
    .
    On Sunday, September 21, 2014 11:15:05 AM UTC-7, Jacob Wenger wrote:

    Hey Sven,

    The $loaded() method is asynchronous because it needs to fetch data from
    Firebase which takes some time. As a result, if you log $scope.events
    outside of the promise returned by $loaded() it is expected to be []. I'm
    not a CoffeeScript expert, but I think you just need to indent your
    console.log to include it in the $loaded() promise:

    $scope.snapshot = fbutil.syncArray("snapshot/" + id)
    $scope.events = []
    $scope.snapshot.$loaded().then (entries) ->
    angular.forEach entries, ((entry) ->
    @push entry
    return
    ), $scope.events
    *console.log "$scope.events: ", $scope.events*

    Jacob
    On Sat, Sep 20, 2014 at 11:08 PM, Sven Woldt wrote:

    I am puzzled as to how to return the data array from the $loaded promise
    back to my $scope.

    $scope.snapshot = fbutil.syncArray("snapshot/" + id)
    $scope.events = []
    $scope.snapshot.$loaded().then (entries) ->
    angular.forEach entries, ((entry) ->
    @push entry
    return
    ), $scope.events
    console.log "$scope.events: ", $scope.events

    console.log output for my $scope array events will be [] and not contain
    the inside the $loaded promise available entries
    I mean an ng-repeat would also bind all entries properly why does the
    thing not work in this case?
    Any help would be greatly appreciated.

    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/7e37c7dc-771f-4dd0-89d3-165e33a26fc9%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/7e37c7dc-771f-4dd0-89d3-165e33a26fc9%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/89bd34ec-ddf1-4d21-9253-ac8f85fa2035%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedSep 21, '14 at 12:52p
activeSep 21, '14 at 6:26p
posts3
users3

People

Translate

site design / logo © 2021 Grokbase