import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions, } from '@angular/http';
@Injectable()
export class RoleService {
headers = new Headers({"Content-Type": "application/json"});
options = new RequestOptions({ headers: this.headers });
constructor(private http: Http) { }
getRoleList(data) {
return this.http.post('http://192.168.10.178:9080/role/getRole', data, this.options)
.toPromise()
.then(res => res.json().data)
.then(data => { return data; });
}
}https://i.stack.imgur.com/nPiK8.png
救救我!如何解决这个问题?
发布于 2017-07-27 08:45:24
试一试
export class RoleService {
options: RequestOptions;
constructor(private http: Http) {
let headers: any = new Headers();
headers.append('Content-Type', 'application/json');
this.options = new RequestOptions({ headers: headers });
}
// ........发布于 2017-07-27 08:47:35
它可能会解决你的问题
import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions, } from '@angular/http';
@Injectable()
export class RoleService {
constructor(private http: Http) { }
getRoleList(data) {
let headers = new Headers({"Content-Type": "application/json"});
let options = new RequestOptions({ headers: headers });
return this.http.post('http://192.168.10.178:9080/role/getRole', data, this.options)
.toPromise()
.then(res => res.json().data)
.then(data => { return data; });
}}发布于 2018-05-13 06:18:08
在Range4.3版本之后,HttpClientModule与HttpClient、HttpHeaders、HttpParams和HttpRequest一起被引入,一些方法已经被废弃,如RequestOptions。
您可以使用来自@angular/common/http的@angular/common/http。
import { HttpClient, HttpRequest, HttpParams, HttpHeaders } from '@angular/common/http';
export class AppComponent {
constructor(private http: HttpClient){}
headers = new HttpHeaders({"Content-Type": "application/json"});
callAPI(){
return this.http.get(URL,{headers}).subscribe(data=>{
console.log(data);
});
}
}您还可以参考:- https://angular.io/api/common/http/
https://stackoverflow.com/questions/45345550
复制相似问题