AIA.factory('LabExerciseService', function ($http, $q) { return { saveLabExerciseAttempt: function (username, labExercieObj) { var deferred = $q.defer(); $http.post('/API/api/Authenticate', JSON.stringify(userInfo), { headers: { 'Content-Type': 'application/json' } }) .success(function (data, status, headers, config) { console.log('success') deferred.resolve(data); }).error(function (data, status, headers, config) { console.log('error') deferred.reject(data); $rootScope.isVisibleLogin = true; $rootScope.errorMessage = data; $("#messageModal").modal('show'); }); return deferred.promise; }, } })