1

I have routes defined in my app.component.ts file as follows

@View({
    templateUrl: 'assets/home.html',
    directives: [AccountManagerComponent, HeaderComponent, ROUTER_DIRECTIVES],

})
@RouteConfig([
    { path: '/home', name: 'Home', component: HomeComponent },
    { path: '/about', name: 'About', component: AboutComponent },    
    { path: '/', name: 'IdentityManager', component: IdentityManagerComponent, useAsDefault: true}    
])

template in home.html is as follow.

<header id="ag-header" class="app-header" role="banner"></header>
<section id="ag-content" class="page-login">
  <router-outlet></router-outlet>
</section>

now i want to disable/hide 'header' element if i am at identitycomponent.

So can i view/hide directives in template based on the route?

sachin kulkarni
  • 737
  • 1
  • 13
  • 26

1 Answers1

0
<header *ngIf="isIdentityManager" id="ag-header" class="app-header" role="banner"></header>
<section id="ag-content" class="page-login">
  <router-outlet></router-outlet>
</section>
constructor( router: Router) {
  router.subscribe(value => {
    this.isIdentityManager = router.currentInstruction.component.routeName == 'IdentityManager';
  });
}

See also In Angular 2 how do you determine the active route?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567