我有另一种使用请求拦截器与$http的方法,它将在一个共同的地方处理所有的url
var app = angular.module('test', []);
app.config(function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'request': function (config) {
config.url = config.url + '?id=123';
return config || $q.when(config);
}
}
});
});
app.controller('test', function ($scope,$http) {
$http.get('Response.txt').success(function (data) { alert(data) }).error(function (fail) {
});
});