Using promises isn't exactly the same in this scenario - as the result depends on multiple service calls being made to populate an array of car makes.
<td ng-show="IsOK(obj)" class="text-center">
<img ng-show="GetStatus(obj)==''" src='@Url.Content("~/img/spinner.gif")' />
<span class="label label-success" ng-bind="GetStatus(obj)"></span>
</td>
IsValid = (car: Car): boolean => {
return (car.Title != null && car.Title != '' &&
car.Condition != null &&
car.StartDate < car.EndDate);
}
GetStatus = (car: Car): string => {
if (!this.IsValid(car)) {
return "Invalid";
}
if (car.Make == null)
{
return '';
}
for (var i = car.Make.length - 1; i >= 0; i--) {
if (car.Make[i].ColourCode == 'G') {
return car.Make[i].Name;
}
}
return '';
}
The calculation of car.Make[i] is performed in another method, which retrieves the result from a service call. Therefore, when car.Make is null, it indicates that the call has not yet been made.
Despite having more calls to the GetStatus() function, some of them consistently return an empty string as a result even after some time when the entire array of car makes has been calculated.