我正在使用Angular 5,我的工作如下
ngOnInit() {
this.activatedRoute.parent.params.subscribe(
params => this.branchId = +params['id']
);
this.validateAssignForm();
this.getConfirmReturnValue();
}
getConfirmReturnValue() {
this.subscription1 = this.confirmService.getReturnValue()
.subscribe(
suc => {
console.log('return value::', suc);
if (suc != 0 && suc.hasOwnProperty('returnValue')) {
this.deleteLanguage(suc); }
});
}
但我不会取消订阅activateRoute我的组件中的任何位置,因为它将取消订阅Angular。
在我的代码中,我通过共享服务订阅BehaviorSubject。现在我在ngOnDestroy(){}函数中取消订阅BehaviorSubject,如下所示
ngOnDestroy() {
this.subscription1.unsubscribe();
}
我的问题是,我可以在销毁当前组件的同时取消订阅BehaviorSubject,例如activateRoute(不使用ngOnDestroy())。