简体   繁体   English

在 'router.events' 回调代码运行后订阅另一个 observable

[英]subscribe to another observable after 'router.events' callback code runs

I have subscribed to router.events and it doesn't complete since I want to to listen all the time and emit on every url change:我已经订阅了router.events并且它没有完成,因为我想一直监听并在每次 url 更改时发出:

    this.router.events
        .filter(event => event instanceof NavigationEnd)
        .startWith({})
        .pairwise()
        .subscribe((events: [NavigationEnd, NavigationEnd]) => {
            if (
                this.breadcrumbs.length > 0 &&
                events[0].url &&
                events[0].url.split("?")[0] === events[1].url.split("?")[0]
            ) {
                return;
            }

            //set breadcrumbs
            let root: ActivatedRoute = this.activatedRoute.root;
            this.breadcrumbs = this.getBreadcrumbs(root);

            this.checkSetIsHomePage();
            this.setBreadcrumbHeight();
        });

but I want my other custom observable to emit after the code above is executed every time, my other observable subscribe is below:但我希望我的其他自定义 observable 在每次执行上述代码后发出,我的其他 observable 订阅如下:

    this.breadcrumbService.additionalBreadcrumbs
        .takeUntil(this.destroy$)
        .subscribe(breadcrumb => {
            if (breadcrumb.index) {
                this.breadcrumbs.splice(breadcrumb.index, 0, breadcrumb);
            } else {
                this.breadcrumbs.push(breadcrumb);
            }
            this.setBreadcrumbHeight();
        });

is there a way to do this without unsubscribing from router.events ?有没有办法在不取消订阅router.events情况下做到这router.events

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM