如果页面未刷新,则不会呈现侧边栏和导航栏

时间:2017-08-09 14:30:09

标签: angular

在下面的代码中,如果页面未刷新,则不会呈现侧边栏和导航栏 组件代码如下所列。

import { Component, OnInit } from '@angular/core';
import {Router} from "@angular/router";

@Component({
    selector: 'app-layout',
    templateUrl: './layout.component.html',
    styleUrls: ['./layout.component.css']
})
export class LayoutComponent implements OnInit {
    constructor(private _router : Router) { }
    IsLoggedIn : boolean = false;
    ngOnInit() {
    if(localStorage.getItem('currentUserId')) this.IsLoggedIn = true;
  }
}

HTML代码列在下面

<div class="wrapper">
    <app-navbar *ngIf="IsLoggedIn==true"></app-navbar>
    <app-sidebar *ngIf="IsLoggedIn==true"></app-sidebar>
    <div class="content-wrapper">
        <app-second-menu *ngIf="IsLoggedIn==true"></app-second-menu>
        <router-outlet></router-outlet>
    </div>
</div>

0 个答案:

没有答案