Angular2-如何使用OR语句? [英] Angular2 - How to use an OR statement?

查看:43
本文介绍了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

这篇关于Angular2-如何使用OR语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆