I’m still a newbie with ionic and am loving how quickly you can get things up and running however I’m stuck and am hoping someone might be kind enough to help me out with something that’s been driving me bonkers. I’m trying to add a custom header to a request to a backend API using ngresource.
I’ve added the following code to my app.js file
.config(function($stateProvider, $httpProvider, $urlRouterProvider, $ionicConfigProvider) {
//code to embed a header in every request
$httpProvider.defaults.headers.common['fantastic-new-header'] = 'header-value';
...
I am then using ionic serve to run on my laptop (have set my backend API to accepte CORS requests) and am seeing the following when I look at the Request Headers using Developer Tools in Chrome.
So you can see the name of the header is being added but the value doesn’t seem to be. I’ve looked all around the web and on Stack Overflow and tried various options but am now completely stumped so am hoping someone might be able to give me a hand.
Yes it should work.
Though this is the app structure promoted by Ionic starter apps, this is far from being adequate for non trivial projects, you may want to have a look at Generator-M-Ionic