From 4260a40628d22d29eddd46291b0717691196be39 Mon Sep 17 00:00:00 2001 From: Wendell Date: Wed, 27 Mar 2019 18:10:37 +0800 Subject: [PATCH] fix(module:breadcrumb): fix auto generate not working in lazy modules (#3174) close #2538 --- .../breadcrumb/nz-breadcrumb.component.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/components/breadcrumb/nz-breadcrumb.component.ts b/components/breadcrumb/nz-breadcrumb.component.ts index 1645a23546e..767c3f9146d 100755 --- a/components/breadcrumb/nz-breadcrumb.component.ts +++ b/components/breadcrumb/nz-breadcrumb.component.ts @@ -12,9 +12,9 @@ import { TemplateRef, ViewEncapsulation } from '@angular/core'; -import { ActivatedRoute, NavigationEnd, Params, PRIMARY_OUTLET, Router } from '@angular/router'; +import { ActivatedRoute, Params, PRIMARY_OUTLET, Router } from '@angular/router'; import { Subject } from 'rxjs'; -import { filter, takeUntil } from 'rxjs/operators'; +import { takeUntil } from 'rxjs/operators'; export const NZ_ROUTE_DATA_BREADCRUMB = 'breadcrumb'; @@ -60,16 +60,10 @@ export class NzBreadCrumbComponent implements OnInit, OnDestroy { if (this.nzAutoGenerate) { try { const activatedRoute = this.injector.get(ActivatedRoute); - const router = this.injector.get(Router); - router.events - .pipe( - filter(e => e instanceof NavigationEnd), - takeUntil(this.destroy$) - ) - .subscribe(() => { - this.breadcrumbs = this.getBreadcrumbs(activatedRoute.root); - this.cd.markForCheck(); - }); + activatedRoute.url.pipe(takeUntil(this.destroy$)).subscribe(() => { + this.breadcrumbs = this.getBreadcrumbs(activatedRoute.root); + this.cd.markForCheck(); + }); } catch (e) { throw new Error('[NG-ZORRO] You should import RouterModule if you want to use NzAutoGenerate'); }