Another method to tackle this issue is by incorporating my solution for the sake of providing a comprehensive response. It is also feasible to associate the this reference with your function. This can be accomplished in two ways, either by utilizing the angular.bind() or the native JavaScript bind to transmit this reference.
For instance:
function MainCtrl($http,myService) {
this.locations = []; // properly initializing
myService.async().then(function(d) {
this.locations = d;
}.bind(this));
}
P.S.: I attempted to enhance your answer by including these solutions to address the issue of varying scopes, but it was rejected. The reason stated was:
This edit was intended to establish communication with the author of the post and does not make sense as an edit. It should have been shared as a comment or an answer
Not to criticize the reviewers, but they seem to overlook the fact that I am unable to post any comments due to my current reputation, and it would not be appropriate to answer a question that has already been addressed.