I have been attempting to retrieve a string from a typescript function -
private _renderListAsync(): string {
let _accHtml: string='';
// Local environment
if (Environment.type === EnvironmentType.Local) {
this._getMockListData()
.then((response) => {
_accHtml = this._renderList(response.value);
alert("1: " + _accHtml)
})
alert("3: " + _accHtml);
return _accHtml;
}
else if (Environment.type == EnvironmentType.SharePoint ||
Environment.type == EnvironmentType.ClassicSharePoint) {
this._getListData()
.then((response) => {
_accHtml = this._renderList(response.value);
alert("2: " + _accHtml);
})
alert("3: " + _accHtml);
return _accHtml;
}
}
Unfortunately, I am only able to receive the string value for alerts labeled as "1" and "2", but not "3" where it displays an empty alert, causing me difficulty in returning _accHtml from the function. What might be the issue here? Additionally, I have noticed that the alert with "3" appears before the ones labeled as "1" and "2". Can anyone explain why this is happening?