简体   繁体   English

Angular2-如何使用OR语句?

[英]Angular2 - How to use an OR statement?

So I am working with active routes in order to manipulate a menu: 因此,我正在使用活动路线来操作菜单:

My menu looks like this: 我的菜单如下所示:

<li [class.router-link-active]="currentPath == '/link1'">
     <a [routerLink]="['link1']"><span>Link 1 option</span></a>
     <ul>
        <li><a [routerLink]="['link1']">Link 1 option</a></li>
        <li><a [routerLink]="['link2']">Link 2 option</a></li>
        <li><a [routerLink]="['link3']">Link 3 option</a></li>
    </ul>
</li>

The main LI element controls the drop down menu style and therefore I need to have an OR statement to ensure the drop down is set correctly if any of the menu collection items are clicked. 主要的LI元素控制下拉菜单的样式,因此,如果单击任何菜单集合项,则需要有一个OR语句来确保正确设置了下拉菜单。

ie

[class.router-link-active]="currentPath == '/link1' OR currentPath == '/link2' OR currentPath == '/link3'"

How do you use OR statement in Angular2? 如何在Angular2中使用OR语句?

“ or”的JavaScript运算符为||

currentPath == '/link1' || currentPath == '/link2' || currentPath == '/link3'

您可以使用数组的indexOf方法,如下所示:

['link1','link2','link3'].indexOf(currentPath) > -1

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

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