我在Angular 2中编写了一个observable.我的代码是这样的:
Observable.create(observer => {
// fetched something from web service
if (some condition) {
observer.next('something');
observer.complete();
}
else { // error with no data
observer.error('something else');
observer.complete(); // Is this required here? Or can I skip this in case of error() ?
}
});
Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 5并使用该subscribe()方法订阅了一个observable .我想知道是否只调用unsubscribe()订阅上的方法就足以清理所有内容,或者我是否也应该调用remove()方法?
代码段:
`
// somewhere in a method
this.s1 = someObservable.subscribe((value) => {
//somecode
});
// in ngOnDestroy
this.s1.unsubscribe(); // should I also call .remove()
Run Code Online (Sandbox Code Playgroud)
`