今天在编程的时候遇到下面的问题:
执行:
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
->next
onError
->error
onCompleted
->complete