你不需要这么做
map
当你使用它的时候
HttpClient
. 只有在您使用
Http
从
@angular/http
HttpClient客户端
json
在响应上获取实际数据,就像使用
Http协议
. 如果你这样做了,因为不会有一个名为
json文件
在响应数据上,它将抛出一个错误。这就是它所做的。
import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class CompetenceService {
public url: string;
constructor(private httpCliente: HttpClient) {}
public createUser(): Observable < any > {
const getHeaders: HttpHeaders = new HttpHeaders({
'Content-Type': 'application/json'
});
return this.httpCliente
.get('http://xxx/xxx/xxx', {
headers: getHeaders
});
}
}