Obwohl ich viele Male versucht habe, aber nicht arbeiten EMIT oder abonnieren.Angular2 Abonnieren Sie nicht über Service arbeiten
Ich möchte app-Header, app-Sidebar und App-footer in
LoginComponent verstecken. Auch * ngIf nicht zu hören GlobalService-Variable.
Vielen Dank im Voraus für Ihre Unterstützung.
/* App HTML */
<app-header *ngIf="global.showHeader"></app-header>
<app-sidebar *ngIf="global.showSidebar"></app-sidebar>
<div class="content-wrapper">
<router-outlet></router-outlet>
</div>
<app-footer *ngIf="global.showFooter"></app-footer>
/* AppComponent */
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
providers: [AppGlobalService]
})
export class AppComponent implements OnInit{
global = {};
constructor(private globalService: AppGlobalService) {
this.globalService.listenUpdated.subscribe(
data => {
this.global = data;
}
);
}
ngOnInit(){
}
}
/* AppGlobalService */
@Injectable()
export class AppGlobalService {
data={
showHeader: true,
showSidebar: true,
showFooter: true
};
listenUpdated = new EventEmitter<any>();
constructor(){}
updateStatus(key: any, value: any) {
this.data[key] = value;
console.log('SERVICE ', this.data); // It's working...
}
}
/* LoginComponent */
@Component({
selector: 'app-login-index',
templateUrl: './index.component.html',
providers: [AppGlobalService]
})
export class LoginIndexComponent implements OnInit {
private data = {};
constructor(public globalService: AppGlobalService) {
this.globalService.updateStatus('showHeader', false);
this.globalService.updateStatus('showSidebar', false);
this.globalService.updateStatus('showFooter', false);
this.globalService.listenUpdated.emit(true);
}
ngOnInit() {
}
}