How to Depreciate .success() and .error() in Angular 1.5

So Angular is depreciating .success() and .error() in $http. For anyone using the two methods, there’s two pieces of good news!

 1. Updating the calls is dead simple.

.then() takes a success function and an error function. You can just refactor your code from:

$http.get(...)
  .success(function(data, ...) {
    ...
  })
  .error(function(data, ...) {
    ...
  });

To:

$http.get(...).then(
  function success(response) {
    var data = response.data;
    ...
  },
  function error(response) {
    var data = response.data;
  });

 2. You can still use it (..for now)

If refactoring isn’t that simple for you, you’re still in luck! You can still enable .success() and .error() through $httpProvider. It defaults to true.. for now.

 Why The Depreciation?

.success() and .error() returns the original promise, as opposed to .then(), which returns a new promise. The two methods in question returns the original promise because of the nature their API design. In order to write this:

$http.get(...)
  .success(function(data, ...) {
    ...
  })
  .error(function(data, ...) {
    ...
  });

One must return the original promise. This leads to awkward promise chaining with the success-error paradigm. You could chain successes together, but the awkwardness comes from being unable to attach an .error() to the chain. Not to mention you’d probably use .then() inside the .success() function anyways. So that’s why in 1.5, Angular will do away with .success() and .error().

 
17
Kudos
 
17
Kudos

Now read this

Javascript Floating Point (im)Precision and Solution

In an exercise to re-implement Javascript’s parseFloat(), I came across a common gotcha. Go ahead, try it yourself: var pointThree = 0.1 + 0.2; console.log(pointThree === 0.3); No, your console isn’t broken. 0.1 + 0.2 ==... Continue →