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

263
Visualizações
Refresh component after doing a router.navigate

I am trying to navigate from one component to another component using :

this.router.navigate(['/path/'], '_blank');

The problem is that the component I am navigating to, is already created and its ngOnInit method is not executed when I navigate back to the page. I am trying to refresh the data showing on the page. This is in the ngOnInit function of the target component:

this.sub = this._DataService.getData().subscribe(data=> {
        this.data= data;
    });

How can I tell the target component, that the data on the page is always refreshed when doing a navigation?

I am using Ag-Grid to show the data in a table. In the NgOnInit function:

this.gridOptions.rowData = this.data;

The component I am originally coming from, is a form to add a new object. After submitting that object, it should redirect to the grid and show the new object. That is why the Grid should be updating its data, but because of some reason, it only does that when I manually refresh it through a context menu action in the grid, not on navigation.

The submit function in the form looks as the following:

 onSubmit(data) {
    this._DataService.addData(data.value).subscribe();
    this.router.navigate(['/data/']);
}
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

If you navigate to the same route and only parameter values change, move the initialization code out from constructor and call it from constructor and when route params change:

constructor(private route:ActivatedRoute) {
  route.params.subscribe(val => this.initialize())
}
about 4 years ago · Santiago Trujillo Relatório

0

I fixed it by changing my onSubmit function to:

  onSubmit(data) {
    this._DataService.addData(data.value).subscribe(data => {
        this.router.navigate(['/path]);
    });
}

Thanks to this question: Angular2 - Redirect after submit does not show updated data

about 4 years ago · Santiago Trujillo Relatório

0

i implemented an redirect component

this.router.navigate(['/redirect/', window.location.pathname]);

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