2

I have the following code on the resolve member in a route:

resolve: {
    loadData: function ($q) {
        var deferred = $q.defer();
        var fbRef = new Firebase("https://myPathToFirebase");
        var auth = new FirebaseSimpleLogin(fbRef, function (error, user) {
            console.log('resolving. ' + user.id + ', Provider: ' + user.provider);
            deferred.resolve();
        });
        console.log('returning..');
        return deferred.promise;
    }
}

The callback within FirebaseSamleLogin is simplified for clarity The logging shows that the code runs as expected. User-id and provider ( facebook) is printed in the callback. My problem is that the deferred.resolved() is not working. The code will not continue to run the controller code and render the template. Exactly as if the deferred was never resolved. I’m kind of stuck here and any help / suggestions would be appreciated Thank you

1
  • Use more verbose traces like console.log("Returning promise..." , deferred.promise) and let us know if that helps. Commented Aug 2, 2013 at 17:50

2 Answers 2

1

I think you may need to wrap the resolve() in $apply() like this

var auth = new FirebaseSimpleLogin(fbRef, function (error, user) {
    console.log('resolving. ' + user.id + ', Provider: ' + user.provider);
    $scope.$apply(function () {
        deferred.resolve();
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Sounds like a good idea and I would like to try. However, this code runs within the config function and the $scope service cannot be injected in this context. I know for sure that deferred. Resolved() does not work when invoked within the FirebaseSimpleLogin. When I move the deferred.resolved() outside the callback, it works fine Of course, the code makes no sense when moved out of the callback
0

And if wrap resolve() in $apply() as @zsong wrote but with $rootscope ?

resolve: {
    loadData: function ($q,$rootscope) {
        var deferred = $q.defer();
        var fbRef = new Firebase("https://myPathToFirebase");
        var auth = new FirebaseSimpleLogin(fbRef, function (error, user) {
            console.log('resolving. ' + user.id + ', Provider: ' + user.provider);
            $rootscope.$apply(deferred.resolve());
        });
        console.log('returning..');
        return deferred.promise;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.