AngularJS globally modify the URL of every request in $http
I have another approach of using request interceptor with $http which will handle all the url's at one common place
<!doctype html>
<html ng-app="test">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body ng-controller="test" >
<!-- tabs -->
<script>
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) {
});
});
</script>
</body>
</html>