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

241
Vistas
Preserve dynamically added <title> in Angular while reloading page

Is there a possibility when refreshing the page to save the tag that has been dynamically added ?

Now, the moment I refresh the page, while loading, the title tag changes to the original one, which I set in the index.html. When the page is loaded, the title tag then comes back to the correct one which is dynamically added. But, I want the title tag to stay the same while the page is refreshing.

This is my app.component.ts:

this.router.events.pipe(
      filter((event) => event instanceof NavigationEnd),
      map(() => this.activatedRoute),
      map((route) => {
        while (route.firstChild) route = route.firstChild;
        return route;
      }),
      filter((route) => route.outlet === 'primary'),
      mergeMap((route) => route.data)
    )
      .subscribe((event) => {
        console.log(event)
        this.translateService.get(event['title']).subscribe(name => {
          this._seoService.updateTitle(name);
        });
        this._seoService.updateDescription(event['description'])
      });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

One approach is to make use of Local Storage to store your dynamic title in there. Here's a simple example where I am storing the title in Local storage and refreshing the page, and retaining my title back. Angular provides a service called Title that allows us dynamically update the title anytime.

<button (click)="setItem()">Click to set a title</button>

<p *ngIf="showInfo" >Refresh the page now :)</p>
export class AppComponent implements OnInit {
  showInfo = false;  

  constructor(private titleService: Title) {}

  ngOnInit() {
    this.getItem();
  }

  setItem() {
    localStorage.setItem('title', 'Hey World!');
    this.showInfo = true;
    this.getItem();
  }

  getItem() {
    if (localStorage.getItem('title'))
      this.titleService.setTitle(localStorage.getItem('title'));
    else this.titleService.setTitle('No title');
  }
}

Here's a live application.

Code - Stackblitz

about 4 years ago · Juan Pablo Isaza 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