加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – BehaviourSubject的distinctUntilChanged()不是函数

发布时间:2020-12-17 07:22:37 所属栏目:安全 来源:网络整理
导读:我是Rxjs的新手 我正在尝试了解BehaviourSubject 下面是我的代码 export interface State { items: Items[]}const defaultState = { items: []};const _store = new BehaviorSubjectState(defaultState);@Injectable()export class Store { private _store =
我是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);
    }
}

当我运行我的项目时,我在我的控制台中收到此错误

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

谁能帮我吗.此外,如果我想要做的是为我的模型对象创建一个商店,所以如果有任何其他更简单的方式随时建议它.

任何帮助表示赞赏.

你必须为此导入整个rxJs库或特定的库.
import 'rxjs/add/operator/distinctUntilChanged';

更新rxjs> 5.5带可管式操作器,

import { distinctUntilChanged } from 'rxjs/operators';

可管理的运算符有助于建筑和树木摇晃

要了解有关benefits of Pipeable operators you may look in here的更多信息.

希望这可以帮助!!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读