Assign value to controller variable asyncronously - AngularJS
<p>I get data from remote request by <code>companiesData.getCompanies()</code> and put it into controller variable.</p>

<p>The controller does not wait for promise resolution, figuring the response array empty.</p>

<p><strong>JS controller :</strong></p>

<pre><code>angular.module('X.Exh', [])

.controller('ExhibitorsController', function($scope, $state, $stateParams, companiesData) {

    this.companies = [];

    companiesData.getCompanies().then(function(response) {
        this.companies = response.data;
console.log(this.companies); // working very well
    });
});
</code></pre>

<p><strong>HTML:</strong></p>

<pre><code> &lt;ion-alpha-scroll ng-model="Exh.companies" key="name" display-key="name" subheader="true" use-complete-alphabet="true"&gt;
&lt;!-- Basically the ion alpha scroll is just doing a ng-repeat for every item, it is not the problem here --&gt;
</code></pre>

<p>Not waiting for the HTTP request, <code>Exh.companies</code> figures empty. (of course if I don't do <code>this.companies = [];</code> at the beginning of my controller, my HTML says that <code>Exh.companies</code> is undefined.</p>

<p>How do I get data properly?</p>