当前状态为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>