0

I am doing an api call using get method, and i need to pass Authorization in header, when i send Authorization token, it call api two times,

here is my code,

GetCount() {
    this.token = 'AbrdhyitT09iubhgsrdhyitT09iubhgsitT09iubhgsrdhyitT09iubhgs459S';
    return this.http.get('MY-API', {
          headers: new Headers({'Authorization': this.token})
        })
}

here is my component

import {Component,ViewChild, AfterViewInit } from '@angular/core';
import {HttpService} from './services/http.service'
import {isDevMode} from "@angular/core";
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
export class AppComponent {
    constructor(private _httpService: HttpService) {

    } 
    GetData() {
        this._httpService.GetCount().subscribe((response:any) => {
            console.log(response);
        })
    }
}

when i remove Authorization from header, it do only one call

Muhammad Arslan
  • 442
  • 1
  • 9
  • 25

0 Answers0