Fulfilled if it is finished, rejected if it has been rejected or is currently rejecting. Pending if it has been resolved to another promise.
$scope.getData = function (url) {
return $http.get(url).then(
function success(response) {
$scope.worked = true
},
function failure(reason) {
$scope.worked = false
}
)
}
// In the Controller
$scope.getFromFactory = function (url) {
myFactory.getData(url).then(
function success() {
$scope.worked = "Working"
}, function failure() {
$scope.worked = "Not working"
})
}
// In the factory
getData: function (url) {
return $http.get(url).then(
function success(response) {
return response.data
},
function failure(reason) {
return reason // Does not return promise
}
)
}
// In the Controller
$scope.getFromFactoryGOOD = function (url) {
myFactory.getDataGOOD(url).then(
function success() {
$scope.worked = true
}, function failure() {
$scope.worked = false
})
}
// In the factory
getDataGOOD: function (url) {
return $http.get(url).then(
function success(response) {
console.log(response.data)
return response.data
}
)
}
function initialize() {
var _url = "/common/timeZoneData.json";
return $http({
method: 'GET',
url: _url
}).then(function successCallback(response) {
for (var i = 0; i < response.data.zones.length; i++) {
moment.tz.add(response.data.zones[i]);
}
}).then(function () {
return getTasks()
}).then(function () {
return addLate()
}).catch(function () {
sweetAlertFactory.note("Error getting time zone information!");
})
}
Every .then returns a function. This maintains the promise so it is not resolved prematurely.