-1
Below I have my class of services, but when performing the search with parameters, the parameters are not passed to the request. Can someone help me?
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import * as moment from 'moment';
export interface LancamentoFiltro{
descricao: string;
dataVencimentoInicio: Date;
dataVencimentoFim: Date;
}
@Injectable({
providedIn: 'root'
})
export class LancamentoService {
lancamentosUrl = 'http://localhost:8080/lancamentos';
constructor(private http: HttpClient) { }
pesquisar(filter: LancamentoFiltro) : Observable<any>{
let params = new HttpParams();
let headers = new HttpHeaders().set('Authorization', 'Basic dmFsZGlvbm9yanVuaW9yQG91dGxvb2suY29tOkJ3aTI4MDI4MSo=');
if(filter.descricao){
params.set('descricao', filter.descricao);
}
if(filter.dataVencimentoInicio){
params.set('dataVencimentoDe', moment(filter.dataVencimentoInicio).format('YYYY-MM-DD'));//uso a biblioteca moment para formatar a data
}
if(filter.dataVencimentoFim){
params.set('dataVencimentoAte', moment(filter.dataVencimentoFim).format('YYYY-MM-DD'));//uso a biblioteca moment para formatar a data
}
return this.http.get<any[]>(`${this.lancamentosUrl}?resumo`,{headers, params});
}
}
need to pass when there are parameters for the HTTP request, using Httpparams, but using the above form, parameters are not passed.
– Valdionor Junior
is in Portuguese
– Valdionor Junior
thanks for reviewing the text, and sorry, I do not have much custom on the site.
– Valdionor Junior
Quiet, read the [tour] to see how it works, and you can also go to [help] for help
– NoobSaibot
Do so:
params = params.set('descricao', filter.descricao);
do the same with others and see if it works.– NoobSaibot
Edited* doing so as suggested the params still comes empty when I step more than one parameter.
– Valdionor Junior
Thank you, yes you solved your suggestion. Thank you very much!
– Valdionor Junior