angularrxjsangular9subscriber

pass argument from subscribe block or error block to 'finally' block


Is there a way to pass argument from subscribe block or error block to 'finally' block without using this keyword. My attempt below which does not work

this.service.create()
    .pipe(first())
    .subscribe (
    (resp) => {
        let argumentToFinally = '';
        if (!!resp.taskInfo) {
            argumentToFinally = this.showError(resp.taskInfo);
        } else {
            close();
            // if else block, 'argumentToFinally' is still ''
        }
    },
    (error) => {
        this.isCallingApi = false;
        argumentToFinally = this.showError('create', undefined, error);
    },
    (argumentToFinally) => {
        close(argumentToFinally)
    });

close(argumentOfFinally?: any) {
    if (!!argumentOfFinally) {
        ..
    }
    this.closeWizard();
}

Solution

  • For more info check -> Using observables to pass values