终于定位到问题的原因了,与 nz-tree-view 无关,是下面的 directive 造成了 nz-tree-view 被重新加载
@Directive({
selector: '[cnbLayoutSidebar]'
})
export class LayoutSidebarDirective implements OnInit {
constructor(
router: Router,
private _sideBarSvc: SideBarService,
private sideBar: TemplateRef<any>) {
router.events
.pipe(
filter(ev => ev instanceof NavigationEnd),
debounceTime(100),
takeUntilDestroyed()
)
.subscribe(() => {
this.updateSidebar();
});
}
ngOnInit() {
this.updateSidebar();
}
updateSidebar() {
if (this.sideBar) {
this._sideBarSvc.$sideBar.next(this.sideBar);
}
}
}
采用的解决方法是把 NavigationEnd
改为 NavigationError