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

251
Views
Conservar el <título> agregado dinámicamente en Angular mientras se recarga la página

¿Existe la posibilidad de guardar la etiqueta que se ha agregado dinámicamente al actualizar la página?

Ahora, en el momento en que actualizo la página, mientras se carga, la etiqueta del título cambia a la original, que configuré en index.html . Cuando se carga la página, la etiqueta del título vuelve a la correcta que se agrega dinámicamente. Pero quiero que la etiqueta del título permanezca igual mientras la página se actualiza.

Esta es mi 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 answers
Answer question

0

Un enfoque es hacer uso del almacenamiento local para almacenar su título dinámico allí. Aquí hay un ejemplo simple en el que almaceno el título en el almacenamiento local y actualizo la página, y retengo mi título. Angular proporciona un servicio llamado Título que nos permite actualizar dinámicamente el título en cualquier momento.

 <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'); } }

Aquí hay una aplicación en vivo .

Código - Stackblitz

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