HappyCoder
HappyCoder

Reputation: 6155

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.

i.e.

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

How do you use OR statement in Angular2?

Upvotes: 0

Views: 143

Answers (2)

yurzui
yurzui

Reputation: 214017

You can use indexOf method of array like this:

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

Upvotes: 1

mdickin
mdickin

Reputation: 2385

The JavaScript operator for "or" is ||

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

Upvotes: 2

Related Questions