【发布时间】:2018-03-13 05:58:45
【问题描述】:
我看到在 Angular 5 中应该以不同的方式使用 rxjs 运算符并从 'rxjs/operators' 导入,但我有点不清楚它应该如何工作。我有类似的东西:
import { Observable } from 'rxjs/Observable';
import { combineLatest, takeUntil } from 'rxjs/operators';
@Component({ ... })
export class FooComponent implements OnInit, OnDestroy {
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route_data = Observable.combineLatest(this.route.params, this.route.data,
(params, data) => ({params,data}));
this.route_data_sub = this.route_data.takeUntil(this.destroyed$).subscribe(
(params_and_data) => {
...
}
}
...
}
但我收到Observable.combineLatest is not a function 错误。如果我以旧方式添加 combineLatest 运算符,它适用于 combineLatest,但现在找不到 takeUntil。 Angular 5 应该如何做到这一点?
我在整个应用程序中都有相当多的 rxjs 代码,但不知道应该如何重写它或如何更改导入。现在一切都必须用 .pipe() 重写吗?
【问题讨论】: