Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
当前状态为Angular中延迟加载路由器的根组件方面模块子级_Angular_State_Router - Fatal编程技术网

当前状态为Angular中延迟加载路由器的根组件方面模块子级

当前状态为Angular中延迟加载路由器的根组件方面模块子级,angular,state,router,Angular,State,Router,我的路由器配置中有这个代码 path: 'printing-documents', component: PrintingDocumentsContentComponent, children: [ { path: '', component: PrintingDocumentsHomeComponent, }, { path: 'new', component: Printing

我的路由器配置中有这个代码

path: 'printing-documents',
    component: PrintingDocumentsContentComponent,
    children: [
      {
        path: '',
        component: PrintingDocumentsHomeComponent,
      },
      {
        path: 'new',
        component: PrintingDocumentsNewComponent,
      },
      {
        path: ':id',
        component: PrintingDocumentsEditComponent,
      },
    ],
在我的
打印文档contentcomponent
中,我有一个html代码

<nb-card>
  <nb-card-header>
    <a class="btn btn-light lamb-button" (click)="onBack()">
      <span class="fa fa-undo lamb-icon" > </span>
    </a>
    {{ titleContainer }}
  </nb-card-header>
  <nb-card-body>
    <router-outlet></router-outlet>
  </nb-card-body>
</nb-card>

{{titleContainer}}
我需要的是当路线是
http://localhost:4200/#/lamb/accounting/configuration/printing-文档
按钮**back()**此按钮隐藏。但是什么时候是
http://localhost:4200/#/lamb/accounting/configuration/printing-文件/新文件
http://localhost:4200/#/lamb/accounting/configuration/printing-文档/15
按钮显示

我知道我必须使用
printing documents contentcomponent
的方法
ngOnInit()
对依赖项
ActivatedRoute
Router
执行一些操作,但我不知道是什么


如果您能检查当前路由的最后一段,我将不胜感激。您需要导入ActivatedRoute、UrlSegment并在组件中使用

在打印文档contentcomponent.component.ts中添加以下代码

在打印文档contentcomponent.component.html中


谢谢。但这只运行一次。我想我需要将这个动作与一个可观察的关联起来,这样每当我使用routerLink导航时,我都会再次运行这个脚本
import { ActivatedRoute, UrlSegment } from '@angular/router';

let flag:boolean=false;
constructor(private route: ActivatedRoute)

ngOnInit() {

    const url: UrlSegment[] = this.route.snapshot.url;

    if(url[0].path=='printing-documents'){
      this.flag = true
    }
     else {
      this.flag = false
     }
<a class="btn btn-light lamb-button" *ngIf="!flag" (click)="onBack()">
    <span class="fa fa-undo lamb-icon" ></span>
  </a>