Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!