title: How to pass Authorization Header Token in api call in angular
body: <p>I am using a get api call to fetch the data from json doc using http. But i have enabled authorization to only token bearer. I want to pass the value of token (which i can get through <code>localStorage.getItem("token");</code>) in my Authorization in the headers when i call the get request. </p>
  
  <p><strong>API.SERVICE.TS</strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Http, Headers, RequestOptions } from '@angular/http';
  import { Observable } from 'rxjs';
  import { HttpClientModule } from '@angular/common/http';
  import { HttpClient, HttpRequest, HttpEventType, HttpHeaders, HttpParams, HttpEvent, HttpErrorResponse, HttpResponse } from '@angular/common/http';
  
  import 'rxjs/add/operator/map';
  
  @Injectable({
    providedIn: 'root'
  })
  export class ApiService {
  
    constructor(private http: Http) { }
  
    getTransferIp(){
      return this.http.get('http://localhost:3003/transferip').map(res =&gt; res.json() );
    }
  
  }
  </code></pre>
  
  <p>Currently i am allowed to fetch the data only when i turn off the auth in my node server get router...
  But i dont want to do that and also without using interceptor</p>
  
  <p>Attatching Node Server Files below...</p>
  
  <p><strong>AUTH.JS</strong></p>
  
  <pre><code>const jwt = require('jsonwebtoken')
  const User = require('../models/user')
  
  const auth = async (req, res, next) =&gt; {
      try {
          const token = req.header('Authorization').replace('Bearer ', '')
          const decoded = jwt.verify(token, 'mango@123')
          const user = await User.findOne({ _id: decoded._id, 'tokens.token': token })
  
          if (!user) {
              throw new Error()
          }
  
          req.token = token
          req.user = user
          next()
      } catch (e) {
          res.status(401).send({ error: 'Please authenticate.' })
      }
  }
  
  module.exports = auth
  </code></pre>
  
  <p><strong>TRANSFERIP.JS (ROUTER)</strong></p>
  
  <pre><code>const express = require('express')
  const TransferIp = require('../models/transferip')
  const auth = require('../middleware/auth')
  const router = new express.Router()
  
  router.post('/transferip', auth, async (req, res) =&gt; {
      const task = new TransferIp({
          ...req.body,
          owner: req.user._id
      })
  
      try {
          await task.save()
          res.status(201).send(task)
      } catch (e) {
          res.status(400).send(e)
      }
  })
  router.get('/transferip', auth, function(req, res, next) {
      TransferIp.find(function (err, events) {
        if (err) return next(err);
        res.json(events);
      });
  });
  
  module.exports = router
  </code></pre>
  
  <p><strong>SCREENSHOT OF SUCCESSFUL GET REQUEST WITH TOKEN USING POSTMAN</strong>
  <a href="https://i.stack.imgur.com/Jf1GQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jf1GQ.png" alt="enter image description here"></a></p>