Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
Ejecutando código después de router.navigate en Angular2

Me pregunto si hay una forma de ejecutar algo después de navegar a una "vista" diferente usando un enrutador angular.

 this.router.navigate(["/search", "1", ""]); // Everything after navigate does not not get executed. this.sideFiltersService.discoverFilter(category);
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

this.router.navigate devuelve una promesa para que simplemente pueda usar:

 this.router.navigate(["/search", "1", ""]).then(()=>{ // do whatever you need after navigation succeeds });

about 4 years ago · Santiago Trujillo Denunciar

0

// In javascript this.router.navigate(["/search", "1", ""]) .then(succeeded => { if(succeeded) { // Do your stuff } else { // Do some other stuff } }) .catch(error => { // Handle the error });
 // In typescript you can use the javascript example as well. // But you can also do: try { let succeeded = await this.router.navigate(["/search", "1", ""]); if(succeeded) { // Do your stuff } else { // Do some other stuff } } catch(error) { // Handle the error }
about 4 years ago · Santiago Trujillo Denunciar

0

No estoy del todo seguro del contexto, pero una opción sería suscribirse a un cambio en la URL usando ActivatedRoute

https://angular.io/docs/ts/latest/guide/router.html#!#ruta activada

Aquí hay un ejemplo:

 ... import { ActivatedRoute } from '@angular/router'; ... private _routerSubscription: any; // Some class or service constructor(private _route: ActivatedRoute){ this._routerSubscription = this._route.url.subscribe(url => { // Your action/function will go here }); }

Hay muchos otros observables a los que puede suscribirse en ActivatedRoute que se enumeran en ese enlace si la URL no es exactamente lo que necesita.

La suscripción se puede hacer en el constructor() o en un ngOnInit() dependiendo de lo que más le convenga, solo recuerde limpiar después de usted mismo y darse de baja en un ngOnDestroy() :)

 this._routerSubscription.unsubscribe();
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda