首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >垫-按钮routerLinkActive替代?

垫-按钮routerLinkActive替代?
EN

Stack Overflow用户
提问于 2019-10-22 10:20:26
回答 1查看 1K关注 0票数 0

我想改变我的垫按钮的颜色时,点击(里面有垫图标)。routerLinkActive="mat-accent"(或其他什么)不工作,我不知道为什么我认为work.Do应该有任何建议?这里我尝试了下面。

代码语言:javascript
复制
   <button style="margin-left:auto;"  mat-button [matMenuTriggerFor]="belowMenu"  routerLinkActive="mat-accent">
        <mat-icon>notifications</mat-icon>
        <span *ngIf="isFinishedSize>0" class="badge">{{isFinishedSize}}</span>
        <mat-menu class="myBorder" #belowMenu="matMenu">
            <h4 style="margin-left:17px;">Pending Tasks</h4>
            <ul class="list-group" *ngFor="let not of notifications;">
                <li *ngIf="!not.isFinished" class="list-group-item">{{not.description}}</li>
            </ul>
            <button style="margin-left:5px;" routerLink="/notifications" mat-button><strong>See the
                    Details</strong>
                <mat-icon>arrow_forward_ios</mat-icon>
            </button>
        </mat-menu>
    </button>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-22 10:26:58

单击按钮时,可以向按钮添加类。将其添加到html中:

代码语言:javascript
复制
(click)="btnClick('someId')" [class.active-btn]="activeId=='someId'"

将此添加到.ts文件中

代码语言:javascript
复制
activeId = '';
btnClick(id: string) {
  this.activeId = id;
}

然后,您可以按照您希望使用的css来设置按钮的样式。

代码语言:javascript
复制
.active-btn {
  color: orange;
  background-color: blue;
} 

最终html:

代码语言:javascript
复制
 <button style="margin-left:auto;"  mat-button [matMenuTriggerFor]="belowMenu"  routerLinkActive="mat-accent" (click)="btnClick('someId')" [class.active-btn]="activeId=='someId'">
        <mat-icon>notifications</mat-icon>
        <span *ngIf="isFinishedSize>0" class="badge">{{isFinishedSize}}</span>
        <mat-menu class="myBorder" #belowMenu="matMenu">
            <h4 style="margin-left:17px;">Pending Tasks</h4>
            <ul class="list-group" *ngFor="let not of notifications;">
                <li *ngIf="!not.isFinished" class="list-group-item">{{not.description}}</li>
            </ul>
            <button style="margin-left:5px;" routerLink="/notifications" mat-button><strong>See the
                    Details</strong>
                <mat-icon>arrow_forward_ios</mat-icon>
            </button>
        </mat-menu>
    </button>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58502087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档