1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| (function(angular) {
'use strict';
angular.module('httpExample', [])
.controller('FetchController', ['$scope', '$http',
function($scope, $http) {
$scope.fetch = function() {
var req = {
method: 'GET',
url: 'url',
headers: {
'Content-Type': 'application/json',
'X-API-DISCOVERY-TOKEN' : '7722ef1e09af4dd5ace354034'
}
}
$http(req).
then(function(response) {
$scope.status = response.status;
$scope.data = response.data;
}, function(response) {
$scope.data = response.data || 'Request failed';
$scope.status = response.status;
});
};
}]);
}); |
Partager