I have a function which executes after button click.
async executeAction(action: Action) {
const proceedingReturnView = this.getCurrentView();
this.srv.execute(action, proceedingReturnView);
}
public getCurrentView(): ViewData {
console.log('I am here 1');
const paramMap = this.activatedRoute.snapshot.paramMap;
const queryParamMap = this.activatedRoute.snapshot.queryParamMap;
return ProceedingViewComponent.getCurrentView(paramMap, queryParamMap, 'PODSTAWOWE', false);
}
getCurrentView() reads details about current view, then pass it as a parameter to the next view, so when I click back button I will return to the view from which I executed the action.
Service execute method:
async execute(a: Action, returnView: any) {
console.log('Recived parameters');
console.table(returnView);
const callerViewPath = returnView ? returnView.viewPath : '';
const callerViewParams = returnView ? JSON.stringify(returnView.viewParams) : '';
this.caseSrv.giveActionCall(
a.id,
callerViewPath,
callerViewParams
).subscribe(
wa => {
if (wa.actionType=== 'PORTAL_CHANGE_VIEW') {
console.log('I am here2');
console.log(wa);
this.portalService.changeView(wa.actionName, this.getChangeViewParams(wa));
}
}
);
}
After first execution everything works fine. Return view details are passed as callerViewPath and callerViewParams. After I use my application back arrow it will return to the point from where I executed action.
But then when I try to execute it another time both return view parameters are empty and it seems that the code started from subscribe in execute() method. First output in console is "I am here2".
I tried to unsubscribe somehow on destroy, but the service always "lives" in application lifecycle.
I am pretty much begginer in RxJS. How can I solve this problem?