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

211
Views
¿Cómo cambio el nombre del botón según el nombre de la ruta sin hacer clic en él?

Quiero cambiar el nombre del botón en mi encabezado. Si voy a iniciar sesión, cambiará el nombre del botón a "Registrarse" y si voy a registrarme, cambiará el nombre del botón a "Iniciar sesión". Quiero cambiar el nombre del botón sin hacer clic en él. Mi problema es que cuando uso this.router.navigate(['login']) en otro componente, el nombre del botón no se cambia a "registrarse". ¿Cómo puedo hacer esto? Aquí está mi código:

encabezado.componente.ts

 changedText() { if(this.router.url.includes('/signup')) { this.text = 'Login'; } else { this.text = 'Signup'; } }

encabezado.componente.html

 <button *ngIf="!IsLoggedIn()" mat-raised-button color="warn" class="add-button me-2" (change)="changedText()" (click)="toggleButton()">{{text}}</button>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

export class AppComponent implements OnInit { public text: string constructor(private route: ActivatedRoute) {} ngOnInit() { this.route.url.subscribe((url) => { this.text = url[0].path == 'signup' ? 'Signup' : 'Login' }); } }
about 4 years ago · Juan Pablo Isaza Report

0

TS:

 readonly label$ = this.router.events .pipe( filter(event => event instanceof NavigationEnd), map(event => event.url.includes('/signup') ? 'Login' : 'Signup') ); constructor(private readonly router: Router) { }

HTML:

 <button *ngIf="!IsLoggedIn()" mat-raised-button color="warn" class="add-button me-2" (click)="toggleButton()">{{label$ | async}}</button>
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!