0

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?

Dan
  • 5,550
  • 20
  • 84
  • 133
HappyCoder
  • 5,675
  • 6
  • 39
  • 69

2 Answers2

1

The JavaScript operator for "or" is ||

currentPath == '/link1' || currentPath == '/link2' || currentPath == '/link3'
mdickin
  • 2,335
  • 21
  • 27
1

You can use indexOf method of array like this:

['link1','link2','link3'].indexOf(currentPath) > -1
yurzui
  • 190,482
  • 29
  • 403
  • 383