Differences between Success and Then Angularjs

Asked

Viewed 1,527 times

10

So far I’ve been using the success to the Http Promises.

Ex:

$http.get(/url).success(function(data){
     console.log("Sucesso");
    })
    .error(function(response, status) {
      console.log("erro " + status);
    });
  }

But today I found an example where the success may be replaced by then:

$http.get(/url).then(function successCallback(response) {
    console.log("Sucesso");
  }, function errorCallback(response) {
    console.log("Erro: "+response);
  });

I would like to know the differences between these two promisses and what are the advantages of using them.

  • http://stackoverflow.com/questions/16385278/angular-httppromise-difference-between-success-error-methods-and-thens-a

  • 2

    You don’t really know the intent of the stackoverflow @Paulohdsousa?

  • 1

    FOR ME is to help others solve programming problems

  • 1

    Always wondered that too @Techies

1 answer

8


The methods success and error are the old way to process Promises for the success and error cases resulting from preview $http.

They do the same thing as the method then() and its two parameters of callback.

In addition, the methods Success and error are now marked as deprecated:

The $http legacy Promise methods Success and error have been deprecated. Use the standard then method Instead. If $httpProvider.useLegacyPromiseExtensions is set to false then These methods will throw $http/legacy error.

Therefore use then(), or write direct callbacks.

Source: https://docs.angularjs.org/api/ng/service/$http

Browser other questions tagged

You are not signed in. Login or sign up in order to post.