在Angular2中对valueChanges进行空订阅 [英] Empty subscribe on valueChanges in Angular2

查看:61
本文介绍了在Angular2中对valueChanges进行空订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种奇怪的情况,如果保留为空,则永远不会触发订阅.

I have this weird case, a subscribe that never fires if left empty.

这不起作用:

this.formGroup.get('unitCount').valueChanges
.do(value => console.log(value))
.subscribe();

这很好时:

this.formGroup.get('unitCount').valueChanges
.do(value => console.log(value))
.subscribe(() => true);

在这里我使用了()=> true ,但是它可以是 false void 0 ,甚至是空对象 {}

Here I used () => true, but it could anything, false, void 0, even an empty object {}

为什么不能保留 subscribe()为空?

推荐答案

您可能具有较旧的RxJS 5版本.这是一个错误,但已经修复.

You probably have a older version of RxJS 5. This was a bug but is already fixed.

由于找不到哪个版本,我无法找到它,但是此PR可能与此有关:

I can't find since what version it works correctly, but this PR could be related to this: https://github.com/ReactiveX/rxjs/pull/1935

否则,请显示您使用的确切RxJS版本.

Otherwise, show what exact RxJS version you're using.

这篇关于在Angular2中对valueChanges进行空订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆