如何仅在特定元素成为目标时应用方法?
有没有办法我只能传递一个应用于多个元素的方法,并且只在特定元素作为目标时触发它?
请参阅下面的示例代码。
aside.component.ts
subNavDisplayTitle ="";
subNavDisplay = "";
changeStyle(event) {
if (this._opened === false) {
this.subNavDisplay = event.type == 'mouseover' ? 'showSubMenu' : 'sub-nav';
this.subNavDisplayTitle = event.type == 'mouseover' ? 'showSubMenuTitle' : 'sidebar-title';
}
}
aside.component.html
<ul class="nav">
<li (mouseover)="changeStyle($event)" (mouseout)="changeStyle($event)">
<div class="sidebar-title" [ngClass]="subNavDisplayTitle">
<b>Maintenance</b>
</div>
<ul [ngClass]="subNavDisplay">
<li routerLinkActive="visitted"><a routerLink="storageentry">Storage</a></li>
<li><a>Document type</a></li>
<li routerLinkActive="visitted"><a routerLink="documentfile">Document file</a></li>
<li><a>User access</a></li>
</ul>
</li>
<li (mouseover)="changeStyle($event)" (mouseout)="changeStyle($event)">
<div class="sidebar-title" [ngClass]="subNavDisplayTitle">
<b>Maintenance</b>
</div>
<ul [ngClass]="subNavDisplay">
<li routerLinkActive="visitted"><a routerLink="uploadfile">File upload</a></li>
<li routerLinkActive="visitted"><a routerLink="borrowdocument">Borrow document</a></li>
<li><a>Document transfer</a></li>
</ul>
</li>
<li (mouseover)="changeStyle($event)" (mouseout)="changeStyle($event)">
<div class="sidebar-title" [ngClass]="subNavDisplayTitle">
<b>Maintenance</b>
</div>
<ul [ngClass]="subNavDisplay">
<li routerLinkActive="visitted"><a routerLink="documentlist">Document list</a></li>
<li routerLinkActive="visitted"><a routerLink="documentlocation">Document location</a></li>
<li><a>Document Transaction</a></li>
</ul>
</li>
</ul>
这是我悬停侧边栏导航时发生的事情 See Sample