SOLVED
I have few components :
- home component, default header, detail component, detail header component
Both headers have different layouts
Let say at Home page, it will display 'Default header',
When user at Detail Page, it will display 'Detail Header'
So my logic is to do some if else in app.component.ts
Unfortunately, it doesn't show as expected.
How to do in Angular2? I have problem to switch the header.
This is my app.component.ts
@Component({
selector: 'app-root',
encapsulation: ViewEncapsulation.None,
styleUrls: ['./main.css'],
template: `
<div class="main-body">
<app-header *ngIf="!showHeaderB()"></app-header>
<detail-header *ngIf="showHeaderB()"></detail-header>
<div class="container">
<small><api-error></api-error></small></div>
<router-outlet></router-outlet>
</div>
<app-footer></app-footer>
<template ngbModalContainer></template>
</div>
`
})
export class AppComponent {
showHeaderB(){
if (this.router.url.startsWith('/detail/')) {
return true;
} else {
return false;
}
}
}