Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度5-鼠标输入显示按钮,鼠标左键隐藏按钮_Angular_Angular Material - Fatal编程技术网

Angular 角度5-鼠标输入显示按钮,鼠标左键隐藏按钮

Angular 角度5-鼠标输入显示按钮,鼠标左键隐藏按钮,angular,angular-material,Angular,Angular Material,当用户将鼠标悬停在列表项上时,我希望显示一个按钮。当用户离开列表项时,我希望按钮不显示 我遇到了一个鼠标事件和一个鼠标事件 .html <mat-list-item (mouseenter)="enter($event)" (mouseleave)="leave($event)" class="chat-message-body" *ngIf="auth._id !== message.author._id" fxLayoutAlign="" dir="ltl"> &

当用户将鼠标悬停在列表项上时,我希望显示一个按钮。当用户离开列表项时,我希望按钮不显示

我遇到了一个鼠标事件和一个鼠标事件

.html

<mat-list-item (mouseenter)="enter($event)" (mouseleave)="leave($event)" class="chat-message-body" *ngIf="auth._id !== message.author._id" fxLayoutAlign=""
    dir="ltl">
    <div matLine>
        <b>{{message.author.profile.username}} </b>
        <span>{{message.created_at | date:'shortTime'}} </span>
    </div>
    <button mat-icon-button>
        <mat-icon aria-label="">keyboard_arrow_down</mat-icon>
    </button>
    <span matLine> {{message.body}} </span>
    <img matListAvatar class="img-box" src="http://via.placeholder.com/30x30" alt="...">
</mat-list-item>
<mat-list dense>
        <ng-template ngFor let-message [ngForOf]="conversation?.messages" let-i="index" let-odd="odd" [ngForTrackBy]="trackById">
            <mat-list-item (mouseenter)="enter(i)" (mouseleave)="leave(i)" class="chat-message-body" *ngIf="auth._id === message.author._id"
                fxLayoutAlign="" dir="rtl">
                <img matListAvatar class="img-box" src="http://via.placeholder.com/30x30" alt="...">
                <button mat-icon-button *ngIf="hoverIndex == i">
                    <mat-icon aria-label="">keyboard_arrow_down</mat-icon>
                </button>
                <div matLine>
                    <b>{{message.author.profile.username}} </b>
                    <span>{{message.created_at | date:'shortTime'}} </span>
                </div>
                <span matLine> {{message.body}} </span>
            </mat-list-item>
        </ng-template>
    </mat-list>
除了声明这些函数外,我不知道如何根据用户是否已输入列表项块或离开列表项来确定此列表项中的按钮的显示和隐藏目标


我已经为此创建了一个解决方案

当用户“mouseenters”mat项目列表块时,我将一个变量设置为true,并在按钮中添加一个ng if,因此当该变量为true时,它将显示;当用户从mat项目列表中“mouseeleaves”时,该变量设置为false。假设您只有一个mat项目列表,则此操作非常有效

拥有多个意味着当用户进入块时,我需要一个变量来存储索引值,并且我确定索引值集是否与im悬停时的索引值集相同。如果是,将显示按钮

.html

<mat-list-item (mouseenter)="enter($event)" (mouseleave)="leave($event)" class="chat-message-body" *ngIf="auth._id !== message.author._id" fxLayoutAlign=""
    dir="ltl">
    <div matLine>
        <b>{{message.author.profile.username}} </b>
        <span>{{message.created_at | date:'shortTime'}} </span>
    </div>
    <button mat-icon-button>
        <mat-icon aria-label="">keyboard_arrow_down</mat-icon>
    </button>
    <span matLine> {{message.body}} </span>
    <img matListAvatar class="img-box" src="http://via.placeholder.com/30x30" alt="...">
</mat-list-item>
<mat-list dense>
        <ng-template ngFor let-message [ngForOf]="conversation?.messages" let-i="index" let-odd="odd" [ngForTrackBy]="trackById">
            <mat-list-item (mouseenter)="enter(i)" (mouseleave)="leave(i)" class="chat-message-body" *ngIf="auth._id === message.author._id"
                fxLayoutAlign="" dir="rtl">
                <img matListAvatar class="img-box" src="http://via.placeholder.com/30x30" alt="...">
                <button mat-icon-button *ngIf="hoverIndex == i">
                    <mat-icon aria-label="">keyboard_arrow_down</mat-icon>
                </button>
                <div matLine>
                    <b>{{message.author.profile.username}} </b>
                    <span>{{message.created_at | date:'shortTime'}} </span>
                </div>
                <span matLine> {{message.body}} </span>
            </mat-list-item>
        </ng-template>
    </mat-list>

此解决方案似乎比尝试查找特定dom元素并向其添加display:block/none更干净。

此块是否位于
ngFor
中?这听起来有点含糊不清。是的,它在NGFOR中。你能为它制作一个stackblitz.com吗?@cgatian现在不需要了,我想我已经解决了