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

156
Views
Cómo cancelar la suscripción de socket io en Angular

Así conecto el cliente al servidor con socket io.

 export class OverviewService { socket:any; readonly uri:string='http://localhost:4000'; constructor(private http: HttpClient) { this.socket = io(this.uri); }

y esto cuando llamo

 getOnPeak(){ this.socket.emit('on_peak/today'); return new Observable((subscriber)=>{ this.socket.on('on_peak/today',(data:any)=>{ subscriber.next(data.onPeak.toFixed(2)) console.log('onPeak:'+data.onPeak.toFixed(2)); }) }) }

resumen.ts

 this.getOnPeekSub=this.overviewService.getOnPeak().subscribe(onPeak => { this.onPeak = onPeak; })

en ngOnDestroy traté de usar removeAllListeners(), removeListeners() y off() pero no funciona.

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

0

getOnPeak(){ this.socket.emit('on_peak/today'); return new Observable((subscriber)=>{ this.socket.on('on_peak/today',(data:any)=>{ subscriber.next(data.onPeak.toFixed(2)) console.log('onPeak:'+data.onPeak.toFixed(2)); }) return function unsubscribe() { this.socket.disconnect() }; }) }

Cuando te des de baja del Observalbe, el enchufe se cerrará. Lea más aquí https://rxjs.dev/guide/observable (Disposición de ejecuciones observables)

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!