Angular,如何在切换时更改<mat-button>中的文本

时间:2017-12-15 08:03:10

标签: angular angular-material

当我切换时,如何更改 mat-button 中的文字

<form class="example-form" style="text-align: center;" [formGroup]="loginForm" (ngSubmit)="buttonClicked()">
  <mat-card [@myAwesomeAnimation]='state' (mouseenter)="animateMe()" (mouseleave)="animateMe()" style="padding: 2vh">
      <input type="text" class="mainInput" style="font-size: 18px;" matInput autofocus shouldLabelFloat="false" placeholder="Insert Your URL Here" autocomplete="off">
  </mat-card>
  <br>
  <button mat-raised-button color="accent"></button>

</form>

2 个答案:

答案 0 :(得分:5)

你可以有一个切换变量吗?

然后按以下方式使用

<button (click)="doToggle()">{{toggle ? 'Toggled':'Not Toggled'}}</button>

然后在TS

toggle:boolean = false;

doToggle():void{
   this.toggle = !this.toggle;
   // Do some other stuff needed
 }

请参阅fiddle

答案 1 :(得分:2)

我不知道切换的含义,但如果您正在寻找文字更改,那么

toggled: boolean = false; // Declare a boolean that holds the toggle value

<!-- Use a ternary condition -->
<button mat-raised-button (click)="toggled = !toggled" color="accent">{{toggled ? 'Toggled' : 'Not toggled'}}</button>