Differences between Success and Then AngularJS

10

So far I've used success to 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 success can be replaced with then :

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

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

    
asked by anonymous 01.12.2015 / 16:47

1 answer

8

The success and error methods are the old way to process the promises for cases of success and error resulting from provider $http .

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

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

  

The 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.

So use then() , or write direct callbacks.

Source: link $ http

    
01.12.2015 / 21:25