Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Angular 4 sending HTTP request twice

Hello and thanks in advance for the help. I just encounter a problem where my request to fetch a single event model is being sent twice.

Here are the functions I use to make get requests, also I'm hard coding the event arg. for testing only of course.

Api.service.ts

public get(path: string, params: URLSearchParams = new URLSearchParams()) : Observable<any> {
    return this.http.get(
        `${environment.api_url}${path}`,
        { headers: this.setHeaders(), search: params })
        .map(res => res.json())
        .share()
        .catch( (error: any) => {
            if(error.status === 401){
                this.router.navigate(['/login']);
                return Observable.throw(new Error(error.status));
            }
        });
}

Event.service.ts

getEvent(id: number)
{
    return this.apiService.get('/event/' + id);
}

EventComponent.ts

export class EventPageComponent implements OnInit
{
event: Event;

constructor(
    private eventServices: EventServices,
    private router: Router
){}

ngOnInit(){
    let id = 1;

    this.eventServices.getEvent(id).subscribe(
        event => {
            this.event = event;
            console.log(this.event);
        },
        err => console.log('Could not load Event with id: ' + id)
    );
}

}

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda