Seeking guidance on a recommended approach.
I have a module where I am configuring some custom headers. It's a simple task:
$httpProvider.defaults.headers.common['token'] = function() {
return token;
};
The token
is a value that needs to be fetched using $http.get()
when the page loads.
Initially, I thought about placing this in my controller. However, upon reflection, it seems more appropriate to handle this in the module configuration during page load where I set my custom headers:
var app = angular.module('app',['ngRoute', 'ngResource'],function($httpProvider) {
// Custom headers
});
I have a two-fold question:
- Is this the most effective method?
- If so, how can I initiate a
$http.get()
request within the module config?