Angular

时间:2018-06-05 20:11:01

标签: angular http

我正在使用get方法进行api调用,我需要在头文件中传递Authorization,当我发送授权令牌时,它会调用api两次,

这是我的代码,

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

这是我的组件

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);
        })
    }
}

当我从标题中删除授权时,它只进行一次调用

0 个答案:

没有答案