获取
src \ app \ app.component.html(2,13)中的错误::类型'AppComponent'上不存在属性'showHead'。
App-Component.ts
import { Component } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public showHead : boolean = false;
constructor(private router: Router) {
// on route change to '/login', set the variable showHead to false
router.events.forEach((event) => {
if (event instanceof NavigationStart) {
if (event['url'] == '/login') {
this.showHead = false;
} else {
this.showHead = true;
}
}
});
}
}
app-component.html
<div class="theme-light">
<header *ngIf="showHead"></header>
<app-menubar *ngIf="showHead"></app-menubar>
<div class="appbody">
<router-outlet></router-outlet>
</div>
<footer *ngIf="showHead"></footer>
</div>
Angular CLI:1.6.6 角度:5.2.10