[英]How to show specific data on mouse hover of specific column into table in angular 8
I have a simple json.我有一个简单的 json。 I need to show specific related span/vehicle_name on mouse hover of specific 'status'.
我需要在特定“状态”的鼠标 hover 上显示特定的相关跨度/车辆名称。 Now when I hover on status(red or yellow) on my table column both vehicle_name is showing.Here I want to show only specific vehicle_name on mouse hover of specific status.
现在,当我在表格列上的状态(红色或黄色)上显示 hover 时,两个车辆名称都显示。这里我只想在特定状态的鼠标 hover 上显示特定车辆名称。 Here is the code below Demo: https://stackblitz.com/edit/angular-d8cwtw?file=src%2Fapp%2Fapp.component.ts
下面是演示代码: https://stackblitz.com/edit/angular-d8cwtw?file=src%2Fapp%2Fapp.component.ts
<div>
<table>
<tr *ngFor="let x of statusdata1;">
<td style="border:1px solid"><span>{{x.vehicle_number}}</span></td>
<td style="border:1px solid"><span (mouseover)="show()" (mouseout)="hide()">{{x.status}}</span><span *ngIf="showit">{{x.vehicle_name}}</span></td>
</tr>
</table>
</div>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
imageSource :any;
statusdata1: any;
showit:boolean = false;
constructor() {}
ngOnInit() {
/* First data */
this.statusdata1 = [{"vehicle_number":1,"vehicle_name":"car","status":"yellow"},{"vehicle_number":2,"vehicle_name":"bus","status":"red"}];
console.log(this.statusdata1);
}
show(){
this.showit= true;
}
hide(){
this.showit= false;
}
}
Good day!再会!
<span (mouseover)="show()" (mouseout)="hide()">{{x.status}}</span>
<span *ngIf="showIt">{{x.vehicle_name}}</span>
So, in this case you showIt
boolean will be bonded to particular component and you needn't do some extra logic.因此,在这种情况下,您
showIt
将绑定到特定组件,您无需执行一些额外的逻辑。
<tr *ngFor="let x of statusdata1; index as idx">
<td style="border:1px solid"><span>{{x.vehicle_number}}</span></td>
<td style="border:1px solid">
<span (mouseover)="show(idx)" (mouseout)="hide(idx)">{{x.status}}</span>
<span *ngIf="showit && idx === currentIdx">{{x.vehicle_name}}</span>
</td>
</tr>
data-content
attribute, check it out: https://davidwalsh.name/css-content-attrdata-content
属性,检查一下: https://davidwalsh.name/css-content-attr .html .html
<table>
<tr *ngFor="let x of statusdata1">
<td>
<span>{{ x.vehicle_number }}</span>
</td>
<td>
<span class="status" [attr.data-line]="x.vehicle_name">
{{ x.status }}
</span>
</td>
</tr>
</table>
.css .css
td {
border: 1px solid;
}
span[data-line]:hover:after {
content: attr(data-line);
}
Demo: https://stackblitz.com/edit/angular-qowzj3演示: https://stackblitz.com/edit/angular-qowzj3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.