Sometimes I have trouble to fetch my data using $http service. And I did not 100% understand the main difference between .success() and .then()
The following is an example that I can fetch the data using $http().then(), but I can't fetch my data using $http().success(). Can anyone explain why?
Code using $http.success() http://jsfiddle.net/xoonpLte/11/
var manuRep = angular.module('manuRep', ['ui.bootstrap']);
manuRep.controller('MyAppController', function($scope, $http) {
$http.get('https://dl.dropboxusercontent.com/u/59954187/jobs.json').
success(function(response) {
$scope.cats = response.data;
}).
error(function(error){
alert(JSON.stringify(error));
return error;
});
});
Code using $http.then() http://jsfiddle.net/xoonpLte/12/
var manuRep = angular.module('manuRep', ['ui.bootstrap']);
manuRep.controller('MyAppController', function($scope, $http) {
$http.get('https://dl.dropboxusercontent.com/u/59954187/jobs.json').
then(function(response) {
$scope.cats = response.data;
});
});
See Question&Answers more detail:os