In my service.ts file i have the following method :
postFiltersAndSearch(param: someType) : boolean{
let test : boolean
//this.bsSearchFilter.next(param)
this.http.post<any[]>(environment.ApiUrl + 'controller/method/', param,this.tokenService.addCors()).subscribe(x => {
if(x.length==0){
//do something...
}
//this.bsSearchResult.next(x)
}, error => {
console.log(error)
test = false
} , ()=> {
console.log()
test = true
})
return test
}
In my other component.ts file i am calling this method like so :
let result= this.searchService.postFiltersAndSearch(someParam)
The problem is my service method always jumps to the final return test
before evaluating the results either from the complete
or error
bloc of the post request and therefore i have undefined
as the result of calling this function.
Is there a way around i can wait for the evaluation of the results before quickly reaching the final return test
?