Angular2 -当两个事件发射器发出时订阅
Angular2 - Subscribe when two event emmitters emit
我的组件有以下代码:
ngOnInit() {
this.route.params.forEach((params: Params) => {
this.codvis = params['id'];
});
this.objects.selectedObject.subscribe(obj => this.selectedEventObjet(obj));
this.sections.selectecSection.subscribe(section => this.selectedEventSection(section));
}
function selectedEventObjet(o) {
this.selectedObj = o;
}
function selectedEventSection(s) {
this.selectedSection = s;
}
所以,现在我想只在设置了selectedObj
和selectedSection
时调用服务,但这不仅仅是简单的:
ngOnInit() {
this.route.params.forEach((params: Params) => {
this.codvis = params['id'];
});
this.objects.selectedObject.subscribe(obj => this.selectedEventObjet(obj));
this.sections.selectecSection.subscribe(section => this.selectedEventSection(section));
this.myService.getItems(this.selectedObj, this.selectedSection)
.subscribe(
items => this.items = items;
);
}
但是我无法获得items
。
我如何确保selectedObj
和selectedSection
被设置为获得items
?
Observable.combineLatest(this.objects.selectedObject, this.sections.selectecSection)
.subscribe(([obj, section]) => this.myService.getItems(obj, section))
您甚至不需要本地处理程序来保存该值,只需直接获取序列。
相关文章:
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- Javascript事件发射器一次处理多个事件
- 无法模拟在 node.js 中使用事件发射器刺激的类中的函数
- Node.js+Mocha+Should.js如何测试事件发射器抛出的错误
- 事件发射器模式如何在Node,sockets.io中工作
- 如何使对象属性函数成为事件发射器
- 您应该如何从节点中的事件发射器继承
- 其他模块中的节点事件发射器
- Angular 2 ES6/7事件发射器更新其他组件
- 绑定事件发射器上的单个事件
- 在模块之间共享的事件发射器
- 为什么在传递/公开事件发射器时需要包装我的事件发射器的 on 函数
- 事件发射器与在 AngularJs 中更新大型数据集时的$watch
- 如何在node中编写事件发射器.js让你创建一个函数“myFunction”,然后在运行时调用成功或失败
- 将立即调用的函数表达式 (IIFE) 与事件发射器一起使用
- 在扩展事件发射器的 ES6 类定义中设置事件侦听器
- 警告:可能检测到事件发射器内存泄漏.添加了 11 个 AppUp > 听众.使用 emitter.setMaxListe
- 节点.js事件发射器源代码的说明
- 从事件发射器继承的对象不会引发事件
- process.on('uncaughtException')的令人困惑的事件发射器/闭包模式