今天在编程的时候遇到下面的问题:
执行:
var subject = new Rx.BehaviorSubject(42);
var subscription = subject.subscribe(
function (x) {
console.log('Next: ' + x.toString());
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 42
subject.onNext(56);
// => Next: 56
报错:
-
"Next: 42"
-
"error"
-
"TypeError: subject.onNext is not a function
at letepecazo.js:54:9"
解决办法:
Due to changes to accommodate the ES7 Observable spec, the API has changed for observables:
onNext->nextonError->erroronCompleted->complete
RxJS BehaviorSubject 使用详解
本文介绍了在使用 RxJS 的 BehaviorSubject 过程中遇到的一个常见错误:TypeError: subject.onNext is not a function。文章详细解释了这一错误的原因,并给出了如何正确调用 BehaviorSubject 的 next 方法来更新值的解决方案。
5241

被折叠的 条评论
为什么被折叠?



