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

209
Visualizações
How do I change the button name depending on the route name without clicking it?

I want to change the name of the button on my header. If I go to login it will change the name of the button to "Signup" and if I go to signup it will change the button name to "Login". I want to change the button name without clicking it. My problem is when I use this.router.navigate(['login']) in another component the button name is not changed to "signup". How can I do this? Here's my code:

header.component.ts

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

header.component.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 Respostas
Responde à pergunta

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

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 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