I try to return the observable after the successful completion of my promise, but this function does not return Observable. To be specific to the code, I want to extract the authentication token from the repository (returns a promise), and after this data is received, generate a Post request for Api (returns Observable). Thus, the exalted text gives an error in the function that "a function whose declared type is neither" void "nor" any "should return the value" below my code,
logout() : Observable<any>{ this.userData.getAuthToken().then((token)=>{ this.token = token; this.headers = new Headers ({ "X-USER-TOKEN": token }); this.options = new RequestOptions ({ headers: this.headers }); var logout_url = "Api logout method"; return this.http.post(logout_url,{},this.options) .map (res => res.json()) }); }
if I just execute the mail request then it returns exactly like that
return this.http.post(logout_url,{},this.options) .map (res => res.json())
but when I try to get the data, it does not return a value from this mail request. Any help would be much appreciated! thanks in advance
source share