我最近升级到 Angular 6 和 rxjs 6,自从升级后,以下动态设置页面标题的代码不再起作用
ngOnInit(): void {
this.router.events
.filter((event) => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map((route) => {
while (route.firstChild) {
route = route.firstChild;
};
return route;
})
.filter((route) => route.outlet === 'primary')
.mergeMap((route) => route.data)
.subscribe((event) => this.titleService.setTitle(event['title']));
};
这给了我一个错误
this.router.events.filter is not a function
我尝试将过滤器包裹在管道中
this.router.events
.pipe(filter((event) => event instanceof NavigationEnd))
但我得到了错误
this.router.events.pipe(...).map is not a function
我已经导入了过滤器
import { filter, mergeMap } from 'rxjs/operators';
我在这里想念什么?