Angular 主机绑定在延迟加载上不起作用
我一直在使用@HostBinding添加类,它在前面工作得很好,但在实现了延迟加载(即延迟加载组件)之后,这些类没有修改Angular 主机绑定在延迟加载上不起作用,angular,lazy-loading,Angular,Lazy Loading,我一直在使用@HostBinding添加类,它在前面工作得很好,但在实现了延迟加载(即延迟加载组件)之后,这些类没有修改 import { HostBinding, HostListener } from '@angular/core'; @Component({ selector: 'body', template: ` <router-outlet></router-outlet> ` }) export clas
import { HostBinding, HostListener } from '@angular/core';
@Component({
selector: 'body',
template: `
<router-outlet></router-outlet>
`
})
export class AppComponent {
@HostBinding('class.login') page: boolean = false;
@HostBinding('class.nav-sm') isFixed: boolean = true;
@HostBinding('class.dashboard') isDashboard: boolean = false;
}
延迟加载后它不工作,任何想法???当以延迟加载方式加载模块时,该模块将是其他模块的子模块,而该模块的
主机将仅是其父模块。如需更多参考,您可以通过
具体问题的解决方案是使用由BaseModule
和延迟加载的模块或事件共享的服务我已经创建了一个服务并注入到模块中,根据需要构建css对象(输出变量、事件发射器)并发出它
在需要时订阅该事件并设置主机绑定
共享服务:
@Output() HostBindingCSS: EventEmitter<any> = new EventEmitter();
getCss() {
return this.HostBindingCSS;
}
setCSS(_page: boolean = false, _isFixed: boolean = true, _isDashboard: boolean = false) {
debugger;
var obj = { page: _page, isFixed: _isFixed, isDasboard: _isDashboard };
this.HostBindingCSS.emit(obj);
}
在需要的页面中,我正在使用服务并调用setCSS方法。您如何修改这些类?你能在一个扑克牌中复制吗?我不明白为什么这不适用于延迟加载。更新了关于我如何使用的代码您是否在某处提供了AppComponent
?在哪里以及如何创建?您的意思是,我应该在共享服务中创建主机绑定并使用它,而不是在AppComponent中创建主机绑定吗?
@Output() HostBindingCSS: EventEmitter<any> = new EventEmitter();
getCss() {
return this.HostBindingCSS;
}
setCSS(_page: boolean = false, _isFixed: boolean = true, _isDashboard: boolean = false) {
debugger;
var obj = { page: _page, isFixed: _isFixed, isDasboard: _isDashboard };
this.HostBindingCSS.emit(obj);
}
export class AppComponent {
@HostBinding('class.login') page: boolean = false;
@HostBinding('class.nav-sm') isFixed: boolean = true;
@HostBinding('class.dashboard') isDashboard: boolean = false;
constructor(private _emsContextService: EMSContextService) {
this._emsContextService.getCss().subscribe(res => {
debugger;
this.page = res.page;
this.isFixed = res.isFixed;
this.isDashboard = res.isDasboard;
});
}
}