如何取消订阅自定义订阅而不取消订阅ngOnDestroy(){}在Angular 5中

时间:2018-04-03 11:01:45

标签: rxjs angular5

我正在使用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())。

0 个答案:

没有答案