1. Use the $http
function FetchController($scope, $http, $templateCache) {
$scope.method = 'GET';
$scope.url = 'http-hello.html';
$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
$http({method: $scope.method, url: $scope.url, cache: $templateCache}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
$scope.updateModel = function(method, url) {
$scope.method = method;
$scope.url = url;
};
}
2.Use the $resource
'use strict';
angular.module('angularFlaskServices', ['ngResource'])
.factory('Post', function($resource) {
return $resource('/api/post/:postId', {}, {
query: {
method: 'GET',
params: { postId: '' },
isArray: true
}
});
})
;