Angular2 - rxjs观察vs处置?
问题描述:
取消订阅和处理有什么区别?Angular2 - rxjs观察vs处置?
例如
// app-service.ts
{Http} from @angular/core;
export class appService {
constructor(private http : Http, fooService : FooService) {}
getAll() {
// do this
this.sub = this.fooService.subscribe(
() => {},
error => throw new Error(error),
() => {}
)
}
ngOnDestroy() {
this.sub.dispose();
}
}
答
它是rxjs4
- rxjs5
差;
在rxjs4
有Disposable
是你们等dispose()
,现在他们Subscription
是你们等unsubscribe()
来源:https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md