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

111
Views
No haga una llamada http en clics de botón posteriores

Tengo un botón en el que el usuario puede hacer clic que hace una llamada http para obtener datos.

Cuando el usuario hace clic en el botón por primera vez, realizo una llamada http. Si el usuario vuelve a hacer clic en el botón, solo proporcione los datos que se obtuvieron anteriormente.

¿Cómo hago eso sin almacenarlo en una variable local explícitamente? He probado algunas cosas pero ninguna parece funcionar. Siempre hace la solicitud http. He intentado usar los operadores "shareReplay" y "share".

 <button (click)=getData()>Click me</button> getData() { source$.pipe( switchMap(sourceVal => { const source2$ = this.getSource2(); const source3$ = this.getSource3(); -------- I do not want this call to be made on subsequent button clicks because it's a reference data return combineLatest([source2$, source3$]) }), map(([source2Val, source3Val]) => { //do some processing return 'done' }) ) }

Estoy usando angular y rxjs.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

puede deshabilitar el botón o evitar el envío de múltiples solicitudes a través de una variable.

 fetching = false; getData() { if(!this.fetching) { this.fetching = true; this.http.get('url').pipe(shareReplay(1), finalize(() => { this.fetching = false; })); } }
about 4 years ago · Juan Pablo Isaza Report
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!