Created
July 27, 2015 05:05
-
-
Save johnz/bd894ec92b697a8d2996 to your computer and use it in GitHub Desktop.
angular http interceptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('interceptor', []) | |
.config(config); | |
config.$inject = ['$httpProvider']; | |
function config($httpProvider) { | |
$httpProvider.interceptors.push('noCacheInterceptor'); | |
} | |
// self register to pollinator app | |
var pollinatorModule = angular.module('pollinator'); | |
pollinatorModule.requires.push('interceptor'); | |
})(); | |
(function() { | |
'use strict'; | |
angular | |
.module('interceptor') | |
.factory('noCacheInterceptor', noCacheInterceptor); | |
function noCacheInterceptor() { | |
return { | |
request: request | |
}; | |
function request(config){ | |
if(config.method.toUpperCase() === 'GET'){ | |
console.log(config.url); | |
config.headers['Cache-Control'] = 'no-cache'; | |
config.headers['Pragma'] = 'no-cache'; | |
} | |
return config; | |
} | |
} | |
})(); | |
(function() { | |
'use strict'; | |
angular | |
.module('pollinator') | |
.run(run); | |
run.$inject = ['customQuestionsClientService']; | |
function run(customQuestionsClientService) { | |
customQuestionsClientService.getQuestions('caee3233-5a5f-48fd-9889-0cac122da4b3', 255, 'c3b4435f-48fc-4de4-8c0f-0e96cc6d6d5e').then(function(result){ | |
console.log('getQuestions 1', result); | |
}); | |
customQuestionsClientService.getQuestions('caee3233-5a5f-48fd-9889-0cac122da4b3', 255, 'c3b4435f-48fc-4de4-8c0f-0e96cc6d6d5e').then(function(result){ | |
console.log('getQuestions 2', result); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment