Nis*_*sai 9 rxjs typescript angular
我是Rxjs的新手我正在尝试理解下面的BehaviourSubject是我的代码
export interface State {
items: Items[]
}
const defaultState = {
items: []
};
const _store = new BehaviorSubject<State>(defaultState);
@Injectable()
export class Store {
private _store = _store;
changes = this._store.distinctUntilChanged()
.do(() => console.log('changes'));
setState(state: State) {
this._store.next(state);
}
getState() : State {
return this._store.value;
}
purge() {
this._store.next(defaultState);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的项目时,我在我的控制台中收到此错误
platform-browser.umd.js:1900 EXCEPTION: Error: Uncaught (in promise):
EXCEPTION: Error during instantiation of Store! (StoreHelper -> Store).
ORIGINAL EXCEPTION: TypeError: this._store.distinctUntilChanged is not a function
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗.此外,如果我想要做的是为我的模型对象创建一个商店,所以如果有任何其他更简单的方式随时建议它.
任何帮助表示赞赏.
Mad*_*jan 28
你必须导入整个rxJs库或特定的库.
import 'rxjs/add/operator/distinctUntilChanged';
Run Code Online (Sandbox Code Playgroud)
使用Pipeable Operators 更新rxjs> 5.5,
import { distinctUntilChanged } from 'rxjs/operators';
Run Code Online (Sandbox Code Playgroud)
可管理的操作员有助于建筑和树木摇晃
要了解有关Pipeable操作员的好处的更多信息,您可以在此处查看.
希望这可以帮助!!
归档时间: |
|
查看次数: |
10566 次 |
最近记录: |