I have this view code:
> <label class="item item-input item-select"> <i class="icon
> ion-android-map icon-color"></i>
> <span class="input-label">Estado</span>
> <select ng-model="meuEstado" required>
> <option value="0">Selecione...</option>
> <option ng-repeat="estado in listaEstados" value="{{ estado.idEstado }}">{{ estado.nmEstado }} - {{
> estado.ufEstado }}</option>
> </select> </label>
Below is my service:
var starter = angular.module('starter.services', []);
starter.factory('appFactory', ['$http', function($http) {
listaEstados: function(local) {
var resultado = null;
var dataToSend = {
type : 'recuperarestados'
};
$http({
url: 'http://....',
method: 'POST',
data: dataToSend
}).success(function(response, status, headers, config) {
return resultado = response;
}).error(function(err, status, headers, config) {
return resultado = null;
});
}
};
}]);
This is the json returned:
[{ "idEstado" : "7", "ufEstado" : "DF", "nmEstado" : "Distrito Federal"},{ "idEstado" : "9", "ufEstado" : "GO", "nmEstado" : "Goiás"},{ "idEstado" : "11", "ufEstado" : "MG", "nmEstado" : "Minas Gerais"},{ "idEstado" : "19", "ufEstado" : "RJ", "nmEstado" : "Rio de Janeiro"},{ "idEstado" : "23", "ufEstado" : "RS", "nmEstado" : "Rio Grande do Sul"},{ "idEstado" : "26", "ufEstado" : "SP", "nmEstado" : "São Paulo"}]
And here is part of my controller:
starter.controller('homeCtrl', ['$scope', '$location', '$state', '$ionicHistory', '$ionicLoading', '$timeout', 'appFactory',
function($scope, $location, $state, $ionicHistory, $ionicLoading, $timeout, appFactory) {
$scope.meuEstado = "0"
$scope.listaEstados = [];
$ionicLoading.show({
templateUrl:"templates/spinner.html",
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 0
});
$scope.listaEstados = appFactory.listaEstados(local);
//Define o tempo para remover o loader,
$timeout(function () {
$ionicLoading.hide();
}, 2000);
}]);
My problem is that my service can get the data from my back-end, but I can´t get this data from my controller, to load my $scope.listaEstados on the view also.
I notice in some posts here in Stackoverflow that I need to use "$scope.$apply", but I have already tried that without success.
Can someone please tell me what kind of change I need to do in my code, to get the data in the controller ?
Thanks.