I get data from remote request by companiesData.getCompanies()
and put it into controller variable.
The controller does not wait for promise resolution, figuring the response array empty.
JS controller :
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
});
});
HTML:
<ion-alpha-scroll ng-model="Exh.companies" key="name" display-key="name" subheader="true" use-complete-alphabet="true">
<!-- Basically the ion alpha scroll is just doing a ng-repeat for every item, it is not the problem here -->
Not waiting for the HTTP request, Exh.companies
figures empty. (of course if I don't do this.companies = [];
at the beginning of my controller, my HTML says that Exh.companies
is undefined.
How do I get data properly?
this inside the unnamed function does not influence original
this.companies
:Please note that
vm.
runs when you usecontrollerAs
pattern.Alternatively you can simply access
$scope
variable: