Difference between success and then in angularJS

  • success() returns the original promise
  • then() returns a new promise

The difference is then() drives sequential operations, since each call returns a new promise.

$http.get(/*...*/).
  then(function seqFunc1(response){/*...*/}).
  then(function seqFunc2(response){/*...*/})
  1. $http.get()
  2. seqFunc1()
  3. seqFunc2()

success() drives parallel operations, since handlers are chained on the same promise.

$http(/*...*/).
  success(function parFunc1(data){/*...*/}).
  success(function parFunc2(data){/*...*/})
  1. $http.get()
  2. parFunc1(), parFunc2() in parallel

Copied from Stackoverflow.

How i used :

then Example :

$scope.findAllUsers = function() {
$scope.loading = true;
userService.getAllUsers().then(function successCallback(data) {
$scope.loading = false;
$scope.userRecords = data.data;

});
}

Success Example:

$scope.findAllUsers = function() {
$scope.loading = true;
userService.getAllUsers().success(function(data) {
$scope.loading = false;
$scope.userRecords = data;

});
}