title: Angular 6 - How do I set a Parent Menu Item To Active using routerLinkActive When Clicking on Its Child Menu Item?
body: <p>I'm using Angular 6 and I've ran into an issue regarding my navigation menu.</p>
  
  <p>When I click on a child-item, only the child item is set to active and not the parent when using routerLinkActive.</p>
  
  <p>I'm wondering how I could set the parent item class to active when selecting its child item in Angular 6?</p>
  
  <p>Lets say I click Floor Maintenance which is the child of Services. Only Floor Maintenance will be set to active but not Services. I'd like to have the Services Button active using routerLinkActive when clicking any of its child items.</p>
  
  <h1>Navigation Menu</h1>
  
  <pre><code>&lt;nav class="navbar navbar-expand-lg navbar-light bg-white thick-border-bottom"&gt;
    &lt;div class="container"&gt;
    &lt;a class="navbar-brand" routerLink=""&gt;&lt;img id="logo" class="img-fluid" src="./assets/logo.svg" alt=""&gt;&lt;/a&gt;
    &lt;button class="navbar-toggler my-3" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown"
      aria-expanded="false" aria-label="Toggle navigation"&gt;
      &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
    &lt;/button&gt;
    &lt;div class="collapse navbar-collapse" id="navbarNavDropdown"&gt;
      &lt;ul class="navbar-nav"&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" routerLink="" routerLinkActive="active" [routerLinkActiveOptions]={exact:true}&gt;Home&lt;span class="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" routerLink="/about" routerLinkActive="active"&gt;About&lt;/a&gt;
        &lt;/li&gt;
  
          &lt;li class="nav-item dropdown"&gt;
          &lt;a class="nav-link dropdown-toggle" routerLink="services" routerLinkActive="active" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true"
            aria-expanded="false"&gt;
              Services
            &lt;/a&gt;
            &lt;div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"&gt;
              &lt;a class="dropdown-item" routerLink="services/janitorial-services" routerLinkActive="active"&gt;Janitorial Services&lt;/a&gt;
              &lt;a class="dropdown-item" routerLink="services/floor-maintenance" routerLinkActive="active"&gt;Floor Maintenance&lt;/a&gt;
              &lt;a class="dropdown-item" routerLink="services/green-cleaning-services" routerLinkActive="active"&gt;Green Cleaning&lt;/a&gt;
            &lt;/div&gt;
          &lt;/li&gt;
  
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" routerLink="/our-difference" routerLinkActive="active"&gt;Our Difference&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" routerLink="/our-clients" routerLinkActive="active"&gt;Our Clients&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" routerLink="/contact" routerLinkActive="active"&gt;Contact&lt;/a&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/nav&gt;
  </code></pre>
  
  <h1>Routing Module</h1>
  
  <pre><code>import { NgModule } from '@angular/core';
  import { RouterModule, Routes } from '@angular/router';
  import { AboutComponent } from './frontend/pages/about/about.component';
  import { HomeComponent } from './frontend/pages/home/home.component';
  import { ServicesComponent } from './frontend/pages/services/services.component';
  import { JanitorialServicesComponent } from './frontend/pages/services/subpages/janitorial-services/janitorial-services.component';
  import { ServiceAreasComponent } from './frontend/pages/service-areas/service-areas.component';
  import { OurClientsComponent } from './frontend/pages/our-clients/our-clients.component';
  import { ContactComponent } from './frontend/pages/contact/contact.component';
  import { FloorMaintenanceComponent } from './frontend/pages/services/subpages/floor-maintenance/floor-maintenance.component';
  import { GreenCleaningServicesComponent } from './frontend/pages/services/subpages/green-cleaning-services/green-cleaning-services.component';
  import { OurDifferenceComponent } from './frontend/pages/our-difference/our-difference.component';
  
  const routes: Routes = [
    { path: '', redirectTo: '/', pathMatch: 'full' },
    { path: '', component: HomeComponent },
    { path: 'about', component: AboutComponent },
    { path: 'services', component: ServicesComponent, 
      children: [
        {path: "janitorial-services", component: JanitorialServicesComponent},
        { path: "green-cleaning-services", component: GreenCleaningServicesComponent},
        { path: "floor-maintenance", component: FloorMaintenanceComponent}
      ] 
    },
    { path: 'our-difference', component: OurDifferenceComponent },
    { path: 'our-clients', component: OurClientsComponent },
    { path: 'contact', component: ContactComponent }
  ];
  @NgModule({
    exports: [RouterModule],
    imports: [RouterModule.forRoot(routes)],
  })
  
  
  export class AppRoutingModule { }
  </code></pre>