Angular 将URLSearchParams转换为HttpParams-角度HttpClient

Angular 将URLSearchParams转换为HttpParams-角度HttpClient,angular,typescript,angular-httpclient,Angular,Typescript,Angular Httpclient,我正在尝试从Angular8上的service.ts将Http更新为HttpClient 我已经更改了HttpClient和HttpHeaders的Http和标头,并且删除了“.pipe(map((response)=>response.json().response));”。选项搜索:params.toString()在HttpParams上不起作用,根据建议,我已改为仅使用params 但这些请求没有发挥应有的作用:( 之前(Http) 从'@angular/core'导入{Injectab

我正在尝试从Angular8上的service.ts将Http更新为HttpClient

我已经更改了HttpClient和HttpHeaders的Http和标头,并且删除了“.pipe(map((response)=>response.json().response));”。选项搜索:params.toString()在HttpParams上不起作用,根据建议,我已改为仅使用params

但这些请求没有发挥应有的作用:(

之前(Http)

从'@angular/core'导入{Injectable,OnDestroy};
从“rxjs”导入{Observable};
从“rxjs/operators”导入{map};
从'@angular/Http'导入{Http,Headers,Jsonp};
从“../app.component”导入{Environment};
//我的组件导入
@可注射()
导出类CompanyService实现OnDestroy{
私有url=Environment.origin;
private urlMainSearch=Environment.MAIN\u SEARCH;
私有urlSearchAll=Environment.SEARCH\u ALL;
私有标头=新标头({
“接受”:“应用程序/cp+json”,
“内容类型”:“应用程序/json”
});
私有头文件=新头文件({
“接受”:“应用程序/cp+json”,
“内容类型”:“多部分/表单数据;边界=某些内容”
});
构造函数(私有http:http,
私有jsonp:jsonp){}
恩贡德斯特罗(){
删除this.http;
}
buscarEmpresas(pesquisa:string):可观察{
返回this.http.get(`${this.url}/companys/${pesquisa}/search`,{headers:this.headers})
.pipe(map((response)=>response.json().response));
}
buscarEmpresasCache(pesquisa:string):可观察{
返回this.http.get(`${this.url}/companys/search?texto=${StringUtils.uncent(pesquisa)}`,{headers:this.headers})
.pipe(map((response)=>response.json().response));
}
Buscarempsimcroservico(pesquisa:string):可观察{
返回this.http.get(`${this.urlMainSearch}/main search?texto=${StringUtils.uncent(pesquisa)}`,{headers:this.headers})
.pipe(map((response)=>response.json().response));
}
getEmpresa(id:number):可观察{
返回this.http.get(`${this.url}/companys/${id}`,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
}
getEmpresaByUrlLink(urlLink:string):可观察{
返回this.http.get(`${this.url}/companys/link/${urlink}`,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
}
getEmpresaRatings(id:number):可观察{
返回this.http.get(`${this.url}/companys/${id}/ratings`,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
}
getOperadora():可观察{
返回this.http.get(`${this.url}/companys/search/operadora/10/1`,{headers:this.headers})
.pipe(map((response)=>response.json().map(empresa=>newempresa(empresa)));
}
getTopEmpresas(类型:number):可观察{
返回this.http.get(`${this.url}/companys/top?type=${type}`,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
}
BUSCEREMPRESASPORTIPO(tipo:编号、pagina:编号、标签:阵列、大陆:阵列、,
paises:Array,cidades:Array):可观察{
//如果(!this.resolverlSearchBug()){
让url=`${this.url}/companys/searchtype?number=25&page=${pagina}&type=${tipo}`;
如果(标记和标记长度>0){
const tag=`&tags=${tags.join(',')}`;
url=url+标签;
}
如果(大陆和大陆长度>0){
常量大陆=`&大陆=${大陆.连接(',')}`;
url=url+大陆;
}
如果(paises&&paises.length>0){
常量pais=`&paises=${paises.join(',')}`;
url=url+pais;
}
如果(cidades&&cidades.length>0){
const cidade=`&cidades=${cidades.join(',')}`;
url=url+cidade;
}
返回this.http.get(url,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
// }
}
buscarTodasEmpresas(页码:编号,文本:字符串,tipos:数组,标记:数组,本地化:数组):
可观察{
让url=`${this.urlSearchAll}/company search all?texto=${texto}&limit=25&offset=${pagina}`;
如果(标记和标记长度>0){
const tag=`&tags=${tags.join(',')}`;
url=url+标签;
}
如果(localizacoes&&localizacoes.length>0){
const localizacao=`&localizacoes=${localizacoes.join(',')}`;
url=url+localizacao;
}
如果(tipos和&tipos.length>0){
常量tipo=`&tipos=${tipos.join(',')}`;
url=url+tipo;
}
返回this.http.get(url,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
}
BUSCEREMPRESSISMILARES(tipo:number,idEmpresaPesquisada:number):可观察{
返回this.http.get(`${this.url}/companys/random searchtype?type=${tipo}&idEmpresaPesquisada=${idEmpresaPesquisada}`,
{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
}
BUSCAMENUTAGS(tipo:编号):可观察{
//console.log(this.resolverlSearchBug());
//如果(!this.resolverlSearchBug()){
//console.log(“查曼多服务……”);
返回this.http.get(`${this.url}/companys/searchtype/filtro?type=${tipo}`,{headers:this.headers})
.pipe(map((response)=>newreturno(response.json());
// }
}
地籍测量(empresa:empresa,isByCadFornecedor:boolean=false):可观测{
返回this.http.post(`${this.url}/companys?isByCadFornecedor=${isByCadFornecedor}`,
stringify(empresa),{headers:this.headers})
.管道(地图)(
params?: HttpParams | { [param: string]: string | string[]; };
{ headers: this.headers, params: params.toString() }
{ headers: this.headers, params }
(method) URLSearchParams.set(name: string, value: string): void

Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
(method) HttpParams.set(param: string, value: string): HttpParams

Replaces the value for a parameter.

@param param — The parameter name.

@param value — The new value.

@return — A new body with the new value.
let params: HttpParams = new HttpParams();
params = params.set('page', page.toString());
params = params.set('size', size.toString());
params = params.set('sort', sort);