长话短说我想在路由器插座旁边显示一个侧边栏,具体取决于正在渲染的组件,我看起来像这样:
<div class="content-wrapper clearfix" [class.show-sidebar]='showSidebar'>
<div class="router-wrapper">
<router-outlet></router-outlet>
</div>
<div class="sidebar-wrapper">
<sidebar></sidebar>
</div>
</div>
&#13;
所以基本上某些组件需要使侧栏消失,我不确定最干净的方法是什么,我的第一个想法是我可以将类绑定到可以注入任何组件的服务中的字段需要隐藏/显示边栏它会起作用,但对我来说似乎并不合适......
答案 0 :(得分:0)
您可以使用路由器插座事件
<router-outlet (activate)="onActivate($event)"></router-outlet>
然后在包含router-outlet的组件中实现onActivate方法:
public onActivate(event : any) {
console.log(event); // here you get hold of all the component and now you can make a variable true false and use ngif or hidden to show or hide the navbar
}