Angular 2 - When a user logs into my website I want to change the header. I have 2 headers components. Hows best to do this?
Currently I have 3 headers and I use "ng-if" in the app.ts template and toggle based off a variable.
This approach currently works however, I hits the app.ts file 3 times because of this.
I'm using angular2 and typescript.
The goal is to have the header change on login as one user type and then if I login as another user type the other header shows. Theres also an external header (3 im toggling in total in the app.ts file).
I basically dont want the app.ts file to get hit 3 times.
This is my code for the app.ts for the top part:
@Component({
selector: 'app',
providers: [UserService, UserProfile]
})
@View({
template: `
<HeaderNavigation *ng-if="!isLoggedIn" [hidden]="!isPageLoadReady"></HeaderNavigation>
<HeaderNavigationLoggedIn *ng-if="isLoggedIn && !isCompanyLogin" [hidden]="!isPageLoadReady"></HeaderNavigationLoggedIn>
<HeaderNavigationLoggedInCompany *ng-if="isLoggedIn && isCompanyLogin" [hidden]="!isPageLoadReady"></HeaderNavigationLoggedInCompany>
<div class="content">
<router-outlet></router-outlet>
</div>
`,
directives: [RouterOutlet, RouterLink, HeaderNavigation, HeaderNavigationLoggedIn, HeaderNavigationLoggedInCompany, NgIf]
})
@RouteConfig([
{ path: '/', redirectTo: '/login' },
{ path: '/login', component: Login, as: 'Login' },
{ path: '/dashboard', component: Dashboard, as: 'Dashboard' }
])
*Notice the 3 headers where ones called: "HeaderNavigationLoggedIn"
Thank you.