解決 subject.onNext is not a function

今天在編程的時候遇到下面的問題:


執行:

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章