I need to dynamically change the text on a button in my header based on the current route. When on the login page, the button should say "Signup" and when on the signup page, it should say "Login". I want this text change to happen without having to click the button. The issue I'm facing is that when I use this.router.navigate(['login'])
in another component, the button text does not update to "Signup". How can I achieve this? Here is 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>