Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 切换到子组件时如何隐藏父组件_Javascript_Angular_Typescript_Routing - Fatal编程技术网

Javascript 切换到子组件时如何隐藏父组件

Javascript 切换到子组件时如何隐藏父组件,javascript,angular,typescript,routing,Javascript,Angular,Typescript,Routing,启动应用程序时,会显示“AppComponent”组件。通过它,使用AuthGuard我转向或不转到模块路径:GalleryModule。我的问题是,当我将子路由GalleryAddComponent或GalleryItemComponent转到GalleryComponent时,我的父亲GalleryComponent没有隐藏,子组件显示在下面。我需要在孩子GalleryAddComponent和GalleryItemComponent的转换过程中,我父亲会隐藏GalleryComponent

启动应用程序时,会显示“AppComponent”组件。通过它,使用
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相关的问题。创建处理库布线的新组件

遵循以下步骤
  • 创建Gallary的主要组件
  • gallery-main.component.html
  • 改变路线-

  • 注意:不要忘记从
    gallery.component.html

    中删除
    ,问题在于
    的位置。它不应该在
    gallery.component.html
    中。如果app.component.html中有
    ,则它将处理路由

    简而言之,只需删除

    可供替代的 如果您正面临与AuthGuard相关的问题。创建处理库布线的新组件

    遵循以下步骤
  • 创建Gallary的主要组件
  • gallery-main.component.html
  • 改变路线-

  • 注意:不要忘记从
    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
    ,效果会更好。