title: Angular JS send common headers with http post redirect
body: <p>I am working with angular js and node express using jwt as authentication mechanism. I used http post in angular as post my username and password and it successfully generate the jwt token. but it is not possible to redirect any other page. How can I set that token as header in other pages through angular JS. </p>
  
  <p>My angular controller is,</p>
  
  <pre><code>  var app = angular.module('authenticate', []);
  
    app.controller('AuthenticateCtrl', function($scope, $http) {
  
        $scope.login = function() {
            option={'name':$scope.name,'password':$scope.password}
            $http({
            method : "POST",
            url : "/api/authenticate",
            data:option
            }).then(function mySucces(response) {
            $scope.message = response.data;
            //$scope.getData(response.data);
            $http.defaults.headers.common['x-access-token'] = response.data;
            window.location.href = '/api/home';
            alert("You are logged in.!");
            }, function myError(response) {
            $scope.message = response.statusText;
            //console.log(response.data);
            console.log(response.statusText);
            var alertPopup = $ionicPopup.alert({
                title: 'Login failed!',
                template: 'Please check your credentials!'
            });
            });
            }
  
    });
  </code></pre>
  
  <p><strong>HTML</strong> script is,</p>
  
  <pre><code>  &lt;body ng-controller="AuthenticateCtrl"&gt;
    &lt;div class="container"&gt;
    &lt;h2&gt;.&lt;/h2&gt;
      &lt;input type="text" name="name" ng-model="name" placeholder="Name" required="" autofocus="" class="form-control" /&gt;&lt;/p&gt;
      &lt;input type="password" name="password" ng-model="password" placeholder="Password" required="" class="form-control" /&gt;&lt;/p&gt;
      &lt;button ng-click="login()" class="btn btn-lg btn-primary btn-block"&gt;Login&lt;/button&gt;
      &lt;hr /&gt;
      {{ message }}
  &lt;/div&gt;
    &lt;/body&gt;
  </code></pre>
  
  <p>and the POST request handling node js part is,</p>
  
  <pre><code>apps.get('/home', function(req, res, next) {
      res.sendFile(dirname+'/public/home.html');
      });
  </code></pre>
  
  <p>But the redirected home page shows </p>
  
  <pre><code>{"success":false,"message":"No token provided."}
  </code></pre>
  
  <p>message. Which is my authentication failure message.
  Anyone please help me to solve this.</p>