Now when executing an ajax request for a url containing a json to store inside a vector, the value of the vector is only populated inside the http method, and outside of the error, I made 2 console.log
following an empty array, follow the code.
myApp.controller('PrincipalController', function($scope, $http) {
$scope.dadosEmail = [];
$http.get('/dados-email.json').success(function(retorno) {
$scope.dadosEmail = retorno;
console.log($scope.dadosEmail);
}).error(function(msg) {
alert('Erro');
});
console.log($scope.dadosEmail);
$scope.ordenaPorNome = function() {
$scope.dadosEmail.sort(function(a, b) {
//Resolve o problema de letras maisculas e minusculas.
a = a.toLowerCase();
b = b.toLowerCase();
if (a.nome > b.nome) {
return 1;
}
if (b.nome > a.nome) {
return -1;
}
return 0;
});
};
});