Angular2-如何使用OR语句?

Angular2-如何使用OR语句?

问题描述:

所以我正在使用活动路线来操纵菜单:

So I am working with active routes in order to manipulate a menu:

我的菜单如下:

<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>

主要的LI元素控制下拉菜单的样式,因此,如果单击任何菜单集合项,我需要使用OR语句来确保下拉菜单的设置正确.

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.

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

如何在Angular2中使用OR语句?

How do you use OR statement in Angular2?

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

You can use indexOf method of array like this:

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