我正在尝试遵循this example,但是在使用combineLatest()
时遇到问题:
Property 'subscribe' does not exist on type 'OperatorFunction<unknown, [unknown, Item[], User[]]>'
这是我的门面:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { combineLatest, distinctUntilChanged, map } from 'rxjs/operators';
export interface User {
test: string;
}
export interface Item {
test: string;
}
interface State {
items: Item[];
users: User[];
}
let _state: State = {
items: [],
users: [],
};
@Injectable()
export class Facade {
private store = new BehaviorSubject<State>(_state);
private state$ = this.store.asObservable();
items$ = this.state$.pipe(map(state => state.items), distinctUntilChanged());
emails$ = this.state$.pipe(map(state => state.users), distinctUntilChanged());
constructor(private http: HttpClient) {
combineLatest(this.items$, this.emails$).subscribe(
([items, users]) => {}
);
}
}
items$
和emails$
都是可观察的。该代码几乎与上面示例中的代码相同,为什么会出现此错误?
答案 0 :(得分:3)
假设您使用的是最新版本的RxJS as per the migration docs:
combineLatest
中的 rxjs/operators
已被弃用。您现在应该直接导入该方法:
import { combineLatest } from 'rxjs';
新版combineLatest()
接受 Observables
数组作为其参数:
combineLatest([this.items$, this.emails$]).subscribe(([items, users]) => {});