[英]Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error
[英]angular2 project rxjs observable error
var bar = Observable.create(function(observer){
try{
console.log('hello');
observer.next(22);
throw new Error('bad bad bad');
setTimeout(function(){
observer.next(300);
observer.complete();
},2000);
}catch(e){
observer.error(e);
}
});
bar.subscribe(
function nextValueHandler(x){
console.log(`out in handler${x}`);
},
function errorHandler(err){
console.log('is wrong'+err);
},
function completeHandler(){
console.log('over');
}
);
我在angular2項目中使用rxjs api 5.0。 此代碼可能是錯誤“檢測到無法訪問的代碼”。 但是如果正確地在'setTimeout ...'之后執行'throw new error ...',為什么之前不能在'setTimeout ...'中執行'theow error ...'?
throw error
將跳轉到catch塊,忽略之后的任何代碼。 像return
語句。 這是JavaScript行為。 因此,永遠不會調用setTimeout。
如果將其添加到setTimeout,則它是回調的,因此它不會檢查代碼是否不可訪問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.