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

303
Views
Angular2 setTimeout devolviendo ZoneTask en lugar de un "Número"

Intentando usar setTimeout en angular2 y quiero borrar el tiempo de espera más tarde.

Pero Angular2 devuelve una "ZoneTask" en lugar de un número

 constructor() { this.name = 'Angular2' this.timeoutId = setTimeout(() => { console.log('hello'); }, 2000); console.log("timeout ID---", this.timeoutId); // Output - ZoneTask {_zone: Zone, runCount: 0, _zoneDelegates: Array[1], _state: "scheduled", type: "macroTask"…}_state: "notScheduled"_zone: Zone_zoneDelegates: nullcallback: function () {cancelFn: nulldata: Objectinvoke: function () {runCount: 0scheduleFn: function scheduleTask(task) {source: "setTimeout"state: (...)type: "macroTask"zone: (...)__proto__: ZoneTask app.ts:24 }

¿Cómo uso el setTimeout normal o cuál es el preferido para usar setTimeout y luego clearTimeout en Angular2?

Plunkr aquí

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Actualizar

Lanzamiento zone@0.8.18 (2017-09-27)

temporizador: arreglo #314, setTimeout/interval debe devolver el timerId original (#894) (aec4bd4)

Versión previa

tienes que llamar

 clearTimeout(this.timeoutId);

El timeoutId que puede obtener llamando

 this.timeoutId.data.handleId

Si desea utilizar setTimeout nativo, puede aprovechar algo como esto:

 this.timeoutId = window['__zone_symbol__setTimeout'](() => { console.log('hello'); }, 2000); // setTimeout will work, but it returns ZoneTask console.log("timeout ID---", this.timeoutId); window['__zone_symbol__clearTimeout'](this.timeoutId); // clearTimeout will also work

Pero no entiendo por qué deseas eso.

about 4 years ago · Santiago Trujillo 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!