请检查以下服务代码。
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { DataJson } from "../models/dataJson";
import { AppSettings } from '../app.settings';
@Injectable()
export class StepsServices {
constructor(private http: Http) {}
postGetPanelists(params, token): Observable<DataJson[]> {
debugger;
let tokenHeaders = new Headers({
'Authorization' : 'Bearer '+token,
'Accept': 'application/json',
});
let tokenOptions = new RequestOptions({ headers: tokenHeaders });
return this.http.post(AppSettings.BASE_API_URL+'demo/demo/', params, tokenOptions)
.map((res: Response) => res.json())
.catch(this.handleError);
}
private handleError(error: any) {
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg);
return Observable.throw(errMsg);
}
}
就像我这样称呼服务
panelists
getPanelistsAPI(){
let params = 'id=AB-12-BC';
let token = atob(localStorage.getItem('token'));
this.stepsServices.postGetPanelists(params, token).subscribe(data =>{
this.panelists= data[0];
});
}
这是网络中的响应数据
这里我们没有看到参数和其他细节。
概述:要求 网址:http://localhost:9090/demo/demo 推荐人政策:no-referrer-when-downgrade
请求标头:显示临时标头 访问控制请求报头:授权 访问控制请求方法:POST原点:http://localhost:4200 User-Agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64) AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 64.0.3282.167 Safari浏览器/ 537.36