如何创建不包含';在angular 7中不包含我的导航?
我需要创建一个组件,其中不包括顶部的导航,但我不知道如何创建。我了解到,您创建的每个组件都是appcomponent的子组件。在如何创建不包含';在angular 7中不包含我的导航?,angular,angular-routing,angular-components,Angular,Angular Routing,Angular Components,我需要创建一个组件,其中不包括顶部的导航,但我不知道如何创建。我了解到,您创建的每个组件都是appcomponent的子组件。在app.component.html中,定义了导航在顶部,然后是内容。此外,还需要通过app routing.module.ts中定义的路由访问组件。有人能帮忙吗 app.component.html: <app-navigation></app-navigation> <div id="content"> <router
app.component.html
中,定义了导航在顶部,然后是内容。此外,还需要通过app routing.module.ts
中定义的路由访问组件。有人能帮忙吗
app.component.html
:
<app-navigation></app-navigation>
<div id="content">
<router-outlet></router-outlet>
</div>
因此,基本上您需要一种从子组件到父组件的通信方式 Angular提供了一种方法,使用输出装饰器和事件发射器。在子组件中声明一个属性,类似于
@Output()
hideTopMenu = new EventEmitter();
在子组件的ngOnInit中,您可以编写
this.hideTopMenu.emit(true);
在父组件的路由器出口中处理(激活)事件
<router-outlet (activate)="onActivate($event)"></router-outlet>
谢谢。请检查此项,而不是在
app.component
中使用app导航
,将其包含在单独的路线中,以便您可以根据需要在适当的位置避免它。
//the reference of current component is provided to the method.
onActivate(componentReference)
{
//check if this component had the output-emitter.
if(componentReference.hideTopMenu)
{
componentReference.hideTopMenu.subscribe((data) => {
if(data)
{
// hide menu logic may go here, maybe you set a boolean value and on template you set *ngIf on menu.
}
})
}
}