我在路由器配置中有这个代码
path: 'printing-documents',
component: PrintingDocumentsContentComponent,
children: [
{
path: '',
component: PrintingDocumentsHomeComponent,
},
{
path: 'new',
component: PrintingDocumentsNewComponent,
},
{
path: ':id',
component: PrintingDocumentsEditComponent,
},
],
在我的PrintingDocumentsContentComponent
我有这段代码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>
我需要的是当路线是http://localhost:4200/#/lamb/accounting/configuration/printing-documents
按钮**后()**这个隐藏。但是当http://localhost:4200/#/lamb/accounting/configuration/printing-documents/new
或http://localhost:4200/#/lamb/accounting/configuration/printing-documents/15
按钮显示时。
我知道我必须在ngOnInit ()
的方法PrintingDocumentsContentComponent
中使用依赖项ActivatedRoute
或Router
执行某些操作,但我不知道是什么。
我将不胜感激
答案 0 :(得分:0)
您可以通过检查当前路线的最后一段来执行此操作。您需要导入ActivatedRoute,UrlSegment并在您的组件中使用。
在您的PrintingDocumentsContentComponent.component.ts中添加以下代码
convertView.setTag(holder);
在PrintingDocumentsContentComponent.component.html
中
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
}