I'm new to angular and migrating a project from angularJS to angular. I'm having below issue with the existing flow.
1.authcomponent:
function FuncBasedOnLogin()
{ authServices.hasLoggedIn(dataService.dataModel.tenant).then(function (isLoggedIn)
{//Do something with response});
}
2.authservice:
function hasLoggedIn(tenant){
return restService.get(url).then(function (response) //This returns new promise
{ //Do something and return boolean response });
} 3.RestService:
function get(url) {
return $http.get(url).then(handleSuccess, handleError);
}
For http calls angularJS was using promises and now angular uses Observable by default. Hence I want to know if we can achieve this by observable way? I'm seeing when I replace then with subscribe in authservice, it's returning subscription which doesn't allow another subscribe down the chain.
I have tried converting toPromise() and achieved the same easily, but want to know if I can do the same using obervable? I have tried ShareReplay as below in authservice & subscribing once in authservice & once again on authcomponent:
let res = this._restService.get<any>(url).pipe(
shareReplay(1)
);
But the problem is it returns same response, but as you can see promise allows me to have modified response down the chain. I might be wrong. Can someone suggest a solution with example?