Angular 行为主体';s distinctUntilChanged()不是函数
我是Rxjs的新手 我正在努力理解这个主题 下面是我的代码Angular 行为主体';s distinctUntilChanged()不是函数,angular,typescript,rxjs,Angular,Typescript,Rxjs,我是Rxjs的新手 我正在努力理解这个主题 下面是我的代码 export interface State { items: Items[] } const defaultState = { items: [] }; const _store = new BehaviorSubject<State>(defaultState); @Injectable() export class Store { private _store = _store;
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);
}
}
有人能帮我吗。另外,如果我试图为我的模型对象创建一个存储,那么如果有其他更简单的方法,请随意推荐
非常感谢您的帮助。您必须导入整个rxJs库或为此而导入的特定库
import 'rxjs/add/operator/distinctUntilChanged';
使用可管道操作符更新rxjs>5.5
import { distinctUntilChanged } from 'rxjs/operators';
管道操作员帮助建筑物和树木晃动
要了解更多关于
希望这有帮助 实际上,您必须导入所有运算符(即
do
和distinctUntilChanged
)以及行为子对象
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/do';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
请参阅plnkr演示:
顺便说一句,我会小心使用诸如private\u-store=\u-store
之类的语句,因为它会使阅读变得非常困难,即使它做了您想要的事情
这是从中生成的
您好,您可能会帮助我,我有webstorm,当我使用可出租操作符时,webstorm会将它们作为“未使用”的导入保存
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/do';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
define(["require", "exports"], function (require, exports) {
"use strict";
var _store = new BehaviorSubject(defaultState);
var Store = (function () {
function Store() {
this._store = _store;
this.changes = this._store.distinctUntilChanged()
.do(function () { return console.log('changes'); });
}
Store.prototype.setState = function (state) {
console.log(_store);
this._store.next(state);
};
Store.prototype.getState = function () {
return this._store.value;
};
Store.prototype.purge = function () {
this._store.next(defaultState);
};
return Store;
}());
exports.Store = Store;
});