【发布时间】:2017-01-04 22:01:43
【问题描述】:
我正在尝试在 Angular 2 中为我的服务使用 observable。
但我收到此错误:
Uncaught TypeError: Cannot read property 'isStopped' of undefined
先睹为快:
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
@Injectable()
export class Service{
getList(){
return new Observable((observer)=>{
observer.next(result);
})
}
}
以及实现:
import ...
@Component({...})
export class List implements OnInit {
list : any[];
list$ : Observable<Array<any>>;
constructor(...){
}
ngOnInit(){
this.list$ = this.Service.getList();
this.list$.subscribe(
(items) => {
this.list = items;
console.log("triggered");
},
(error)=>{
console.error(error);
},
()=>{
console.log("completed");
}
);
}
}
有人遇到过这个错误吗?我找不到任何相关内容。
================================================ =================
编辑:
对不起,这是“isStopped”的来源: https://github.com/ReactiveX/rxjs/blob/master/src/Subscriber.ts#L94
来自 rxjs 库。
【问题讨论】:
-
发布的代码中的“isStopped”在哪里?
-
对不起,这是“isStopped”的来源:github.com/ReactiveX/rxjs/blob/master/src/Subscriber.ts#L94 来自 rxjs 库。
标签: javascript angular observable subscriber