I have encountered a situation where I need to ensure that the result of two methods is awaited before proceeding with the rest of the code execution. I attempted to use the async keyword before the function name and await before the GetNavigationData() method, but unfortunately, this did not yield the desired results. In an effort to troubleshoot, I also attempted to print out the values to understand what was happening. The expected data should be:
API method
Regular method
However, the actual results are as follows: https://i.sstatic.net/EAi6U.png
getFlatNavigation(navigation) {
if (this.navigation.length == 0) {
console.log(this.GetNavigationData());
console.log('Regular method');
}
}
GetNavigationData() {
let applicationMenuData = new InitializeAppRequest();
this.http.post(this.appGlobal.BASE_SERVER_ADDRESS + 'api/AppServer/InitializeApp', applicationMenuData).subscribe((res) => {
console.log('API method');
return res['AplicationMenuData'];
});
}
What steps should be taken in order to achieve the expected results?