Javascript 切换到子组件时如何隐藏父组件
启动应用程序时,会显示“AppComponent”组件。通过它,使用Javascript 切换到子组件时如何隐藏父组件,javascript,angular,typescript,routing,Javascript,Angular,Typescript,Routing,启动应用程序时,会显示“AppComponent”组件。通过它,使用AuthGuard我转向或不转到模块路径:GalleryModule。我的问题是,当我将子路由GalleryAddComponent或GalleryItemComponent转到GalleryComponent时,我的父亲GalleryComponent没有隐藏,子组件显示在下面。我需要在孩子GalleryAddComponent和GalleryItemComponent的转换过程中,我父亲会隐藏GalleryComponent
AuthGuard
我转向或不转到模块路径:GalleryModule
。我的问题是,当我将子路由GalleryAddComponent
或GalleryItemComponent
转到GalleryComponent
时,我的父亲GalleryComponent
没有隐藏,子组件显示在下面。我需要在孩子GalleryAddComponent
和GalleryItemComponent
的转换过程中,我父亲会隐藏GalleryComponent
。如何实施
我的项目结构:
批准模块:
public navigation = new Subject<any>();
public navigation$ = this.navigation.asObservable();
<div *ngIf="displayGalleryContent"></div>
const批准:路由=[
{
路径:“”,
路径匹配:“已满”,
重定向到:“应用程序根”
},
];
@NGD模块({
进口:[
公共模块,
RouterModule.forRoot(批准)
],
导出:[路由模块],
})
因此您必须从GalleryRoutingModule中删除子路由。和来自Gallery组件的路由器插座。并且需要在GalleryRoutingModule中使路由正常(无嵌套/子路由),因此您必须从GalleryRoutingModule中删除子路由。和来自Gallery组件的路由器插座。并且需要在GalleryRoutingModule中使路由正常(无嵌套/子路由)问题在于
的位置。它不应该在gallery.component.html
中。如果app.component.html中有
,则它将处理路由
简而言之,只需删除
可供替代的
如果您正面临与AuthGuard相关的问题。创建处理库布线的新组件
遵循以下步骤
注意:不要忘记从
gallery.component.html
中删除
,问题在于
的位置。它不应该在gallery.component.html
中。如果app.component.html中有
,则它将处理路由
简而言之,只需删除
可供替代的
如果您正面临与AuthGuard相关的问题。创建处理库布线的新组件
遵循以下步骤
注意:不要忘记从
gallery.component.html
服务中删除
public navigation = new Subject<any>();
public navigation$ = this.navigation.asObservable();
<div *ngIf="displayGalleryContent"></div>
在Gallery组件中,您可以订阅以侦听更改
public displayGalleryContent = true;
this.service.navigation$.subscribe((isreached)=>{
if(isreached){
this.displayGalleryContent = true;
}
});
模板:
public navigation = new Subject<any>();
public navigation$ = this.navigation.asObservable();
<div *ngIf="displayGalleryContent"></div>
服务:
public navigation = new Subject<any>();
public navigation$ = this.navigation.asObservable();
<div *ngIf="displayGalleryContent"></div>
在Gallery组件中,您可以订阅以侦听更改
public displayGalleryContent = true;
this.service.navigation$.subscribe((isreached)=>{
if(isreached){
this.displayGalleryContent = true;
}
});
模板:
public navigation = new Subject<any>();
public navigation$ = this.navigation.asObservable();
<div *ngIf="displayGalleryContent"></div>
似乎您需要路由器插座
。请在您的问题中添加app.component.html
。@User3250我在app.component中有路由器出口,我需要隐藏GalleryComponent当我转到GalleryAddComponent或GalleryItemComponent时,您似乎需要路由器出口
。请在您的问题中添加app.component.html
。@User3250我在app.component中有路由器出口我需要隐藏GalleryComponent当我转到GalleryAddComponent或GalleryItemComponent时我以前做过,然后我需要写“canActivate:[AuthGuard]”对于每个组件,这是一个配音。您可以再做一件事,在指向Gallerycomponent htmlI的子路由中创建一个默认路由,然后我需要编写“canActivate:[AuthGuard]”对于每个组件,这是一个配音。您可以再做一件事,在子路由中创建一个默认路由,该路由指向我在app.component.html中拥有的Gallerycomponent html,但如果我从gallery.component.html中删除,则在导航Gallerycomponent时,我看不到我的子组件更新了答案。如果你可以共享你的app.component.html
,那就更好了。是的,我在app.component.html中有,但是如果我从gallery.component.html中删除了,那么在GalleryComponent的子组件中导航时,我就看不到它们了。更新了答案。如果您可以共享您的app.component.html
,效果会更好。