简体   繁体   English

Angular 材料标签 isActive

[英]Angular material tabs isActive

I'm trying to use tabs from angular material ( https://material.angular.io/components/tabs/api )我正在尝试使用 angular 材料中的标签( https://material.angular.io/components/tabs/api

Doc specifies that there is an isActive property but I don't know how to use it, how do I change my image (when the tab is active) what am I doing wrong in my exemple? DOC指定有一个ISACTIVE属性,但我不知道如何使用它,我该如何更改图像(当Tab处于活动状态时)我在我的范围内做错了什么?

<mat-tab label="all" isActive="iconAllOn=true">
    <ng-template mat-tab-label>
        <div (mouseover)="iconAllOn=true" (mouseout)="iconAllOn=false">
            <img class="logoNavBar" *ngIf="!iconAllOn" [src]="imagePathAllOff">
            <img class="logoNavBar" *ngIf="iconAllOn" [src]="imagePathAllOn">
        </div>
    </ng-template> 
    Content 1
</mat-tab>

isActive is not a @Input property, you can't set the value to it. isActive不是@Input属性,您不能为其设置值。 Check the following example, here a form field is used to set the active tab.检查以下示例,此处使用表单字段设置活动选项卡。 https://stackblitz.com/angular/dgkalqaqdlv?file=src%2Fapp%2Ftab-group-dynamic-example.ts https://stackblitz.com/angular/dgkalqaqdlv?file=src%2Fapp%2Ftab-group-dynamic-example.ts

MatTabGroup supports setting up the selected index. MatTabGroup支持设置选中的索引。 API API

Are you trying to set some style on mouseHover?你想在 mouseHover 上设置一些样式吗? Active tab styling can be done in a different way活动标签样式可以以不同的方式完成

Here is an example:这是一个例子:

https://stackblitz.com/angular/mkjxrrgbdak?file=src%2Fstyles.scss https://stackblitz.com/angular/mkjxrrgbdak?file=src%2Fstyles.scss

I have added basic styling, it is not a proper way to style tab but it can be achieved.我添加了基本样式,这不是设置标签样式的正确方法,但可以实现。

A little late here, but you could do something like the following.这里有点晚了,但是您可以执行以下操作。 Not entirely sure how you want it to behave.不完全确定您希望它如何表现。

<mat-tab #allTab label="all">
    <ng-template mat-tab-label>
        <div (mouseover)="iconAllOn = true" (mouseout)="iconAllOn = false">
            <img class="logoNavBar" *ngIf="!iconAllOn || !allTab.isActive" [src]="imagePathAllOff">
            <img class="logoNavBar" *ngIf="iconAllOn || allTab.isActive" [src]="imagePathAllOn">
        </div>
    </ng-template> 
    Content 1
</mat-tab>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM