Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda