jbutko
7/31/2014 - 7:44 AM

AngularJS: How to execute a controller function AFTER completion of AJAX call in a service

AngularJS: How to execute a controller function AFTER completion of AJAX call in a service

this.loginUser = function(checkUser) {
    var deferred = $q.defer();
    Parse.User.logIn(checkUser.username, checkUser.password, {
        success: function(user) {
            $rootScope.$apply(function (){
                $rootScope.currentUser = user;
            });
            deferred.resolve();
        }
    });
    return deferred.promise;
};
//http://stackoverflow.com/questions/23546593/angularjs-how-to-execute-a-controller-function-after-completion-of-ajax-call-in
$scope.logIn = function(){
    authenticationService.loginUser($scope.checkUser).then(function() {
        console.log($rootScope.currentUser));
    });
};