如何根据路由名称更改按钮名称而不单击它?
我想更改标题上的按钮的名称。如果我登录,它将更改按钮的名称为“注册”,如果我去注册,则将按钮名称更改为“登录”。我想在不单击的情况下更改按钮名称。我的问题是,当我使用this.router.navigate(['login'])
在另一个组件中,按钮名称未更改为“ Inbisup”。我该怎么做?这是我的代码:
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ts:
html:
TS:
HTML: