The $http
returns a promise; you can define its success or error depending on this promise. Many think that these functions are a standard part of promise—but in reality, they are not as they seem to be.
Using promise means you are calling then()
. It takes two parameters—a callback function for success and a callback function for failure.
Imagine this code:
$http.get("/api/tv/serials/sherlockHolmes") .success(function(name) { console.log("The tele serial name is : " + name); }) .error(function(response, status) { console.log("Request failed " + response + " status code: " + status); };
This can be rewritten as:
$http.get("/api/tv/serials/sherlockHolmes") .success(function(name) { console.log("The tele serial name is : " + name); }) .error(function(response, status) { console.log("Request failed " + response + " status code: " + status); }; $http.get("/api/tv/serials/sherlockHolmes") .then(function(response) { console.log("The tele serial...