Rxjs主题next或onNext [英] Rxjs Subject next or onNext

查看:265
本文介绍了Rxjs主题next或onNext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在rxjs方面,我是新手,请耐心等待. 例如在本教程中 http://blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services-pitfalls-to-avoid/ 但是我在ng-book中看到了相同的代码

I'm quite new at rxjs stuff be patience. For example in this tutorial http://blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services-pitfalls-to-avoid/ but I saw the same code in the ng-book

我可以看到

let subject = new Rx.Subject();
subject.subscribe(value => console.log('Received new subject value: '))
subject.next(newValue);

但是如果我将代码放入浏览器中,我就拥有

but if I put the code in the browser I've got

s ubject.next不是函数

所以,如果我看一下文档 https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/subjects.md

so if I take a look to the doc https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/subjects.md

var subject = new Rx.Subject();
subject.subscribe(value => console.log('Received new subject value: ',value))
subject.onNext(2);

您能解释一下为什么教程和书吗 正在使用下一个吗?我想念什么?

Can you explain me why the tutorial and the book are using next ? What am I missing ?

推荐答案

似乎您使用了错误的rxjs版本(4.x). Angular2使用rxjs 5 https://github.com/ReactiveX/rxjs/

Seems you're using the wrong rxjs version (4.x). Angular2 uses rxjs 5 https://github.com/ReactiveX/rxjs/

另请参见 http://reactivex.io/rxjs/

这篇关于Rxjs主题next或onNext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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