- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 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';
使用 Pipeable Operators 更新 rxjs > 5.5,
import { distinctUntilChanged } from 'rxjs/operators';
Pipeable 运算符有助于构建和摇树。
要了解更多关于 benefits of Pipeable operators you may look in here 的信息.
希望这对您有所帮助!
关于angular - BehaviourSubject 的 distinctUntilChanged() 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39667133/
我正在尝试模拟组件测试中的服务依赖项,该服务具有我试图模拟的行为主题属性。 我的服务如下: export class DatePickerService { public date: moment
我像这样创建BehaviorSubject: private val viewStateSubject: BehaviorSubject = BehaviorSubject.create() 后来我通
我正在使用 BehaviourSubject纯粹作为触发器,所以有效载荷并不重要。主题应该在订阅时“触发”(调用 next )(一个简单的 Subject 是行不通的!)。原则上有一个 Behavio
我正在构建一个 Angular2 应用程序,并且有两个 BehaviourSubjects我想在逻辑上合并为一个订阅。我正在发出两个 http 请求,并希望在它们都返回时触发一个事件。我在看 fork
我有 BehaviourSubject,我想用最后发出的值刷新项目。我可以在下面做例子, func refreshCurrent() { do { let items = t
我正在开发一项用户服务,通过用户的 user_id 跟踪用户。它首先检查 user_id 是否存在于他们的 cookie 中,如果不存在,它会向 api 发出获取请求以创建一个新的并在响应中返回 id
我正在尝试使用 Angular 服务通过可观察来存储和通信数据。 这是我的服务 public _currentLegal = new BehaviorSubject({ name: 'init',
我有一个带有 Angular 和 typescript 的简单表格。我将表数据从父类发送到子类(包括表),在此示例中数据名称是 _domainData。它正在正确获取数据,但我想在表上显示它,但我不知
我是 Rxjs 新手我正在尝试了解 BehaviourSubject下面是我的代码 export interface State { items: Items[] } const defaul
使用流构建器并将其流设置为 BehaviourSubject 的流,无论何时重建父窗口部件并调用 streamBuilder 的构建器函数,快照连接状态都在等待,尽管流中有以前的数据,但快照具有没有数
有一项服务用于读取初始持久值 - “settings”,并通过可观察的“settings$”将它们提供给订阅者 - 组件。多个组件使用“settings$”可观察值来检索初始持久值并进一步在它们之间交
我是 swift 和 rxSwfit 世界的新手,我正在寻求对当前解决方案的建议或批评,例如同步博客文章、类别、作者或我们需要的任何内容。 以这种经典情况为例:一个可观察量向每个订阅者提供模型中存在的
前几天我注意到了一些事情。我订阅了 @ngrx/effects 中的 Actions 流。我注意到(对我来说是一个问题)一个组件,它订阅 Actions 晚了,接收到最后一个调度的 Action 。我
因此,我有一个使用从服务中获取的数据填充的表,该服务器内的方法连接到 NodeJS API。 我尝试在我的服务上使用 BehaviourSubject,但我将其初始化为未定义,因为数据是从后端获取的:
当我测试我的代码时,我不小心遇到了意想不到的突变......或者也许......我只是做错了...... 用户 constructor( public id: number, public educa
目前我正在使用 RxKotlin 在 Kotlin 中构建一个项目。我的 Rx 背景主要基于 RxJS。 我经常用于在 Typescript 中创建热可观察对象的模式看起来类似于: private
我是一名优秀的程序员,十分优秀!