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,836
  • 22
  • 86
  • 140
HappyCoder
  • 5,985
  • 6
  • 42
  • 73

2 Answers2

2

The JavaScript operator for "or" is ||

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

You can use indexOf method of array like this:

['link1','link2','link3'].indexOf(currentPath) > -1
yurzui
  • 205,937
  • 32
  • 433
  • 399