使用Google Chrome,请求中没有可用的角度数据

时间:2018-07-12 08:37:29

标签: angular get

google chrome告诉我,在angular6中使用get请求时,该请求无可用数据,这是我的代码:

获取请求服务:

import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})
export class TableRequestsService {

  constructor(private myhttp:HttpClient) { }

  getTableRequests(){
    console.log(localStorage.getItem('token'));
    return this.myhttp.get('http://192.168.204.54:8080/hp-hup-testing-0.0.1-SNAPSHOT/api/v1/request?hubId=1');
  }
}

requests.ts:

 ngOnInit() {
      this.requestsTable.getTableRequests().subscribe(
        (data)=>{
            console.log(data['token']);
        }
      )
  }

拦截器类:

  constructor() {}
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    request = request.clone({
      setHeaders: {
        Authorization: `Bearer ${localStorage.getItem('token').toString().slice(1,-1)}`
      }
    });
    return next.handle(request);
  }

0 个答案:

没有答案