0
I have a select component
<div class="form-group col-md-4">
<label>Entidade:</label>
<select ng-model="distrito.entidade.idEntidade" class="form-control">
<option value="{{dis.entidade.idEntidade}}" ng-repeat="dis in distritos">{{dis.entidade.nome}}</option>
</select>
</div>
My controller class
app.controller("buscaDistritoController", function($scope, $http) {
$scope.distritos = [];
$scope.distrito = {}; // binding com o form
carregarDistritos = function() {
token = localStorage.getItem("userToken");
$http({
method : 'GET',
url : 'http://localhost:8080/user/distritos'
}).then(function(response) {
$scope.distritos = response.data;
}, function(response) {
console.log(response.data);
console.log(response.status);
});
};
$scope.salvarDistritos = function() {
if ($scope.frmDistrito.$valid) {
$http({
method : 'POST',
url : 'http://localhost:8080/user/distritos',
data : $scope.distrito
}).then(function(response) {
carregarDistritos();
$scope.distrito = {};
}, function(response) {
console.log(response.data);
console.log(response.status);
});
} else {
alert("Campos com * são de preenchimento obrigatório");
}
};
$scope.excluirDistritos = function(distrito) {
bootbox.confirm({
message : "Deseja excluir o registro permanentemente ?",
buttons : {
cancel : {
label : '<i class="fa fa-times"></i> Cancelar'
},
confirm : {
label : '<i class="fa fa-check"></i> Sim'
}
},
callback : function(result) {
if (result == true) {
$http({
method : 'DELETE',
url : 'http://localhost:8080/user/distritos/'+distrito.id
}).then(function(response) {
pos = $scope.distritos.indexOf(distrito);
$scope.distritos.splice(pos, 1);
}, function(response) {
console.log(response.data);
console.log(response.status);
});
}
}
});
};
$scope.alterarDistritos = function(dis) {
$scope.distrito = angular.copy(dis);
};
$scope.cancelarAlteracaoDistritos = function() {
$scope.distrito = {};
};
carregarDistritos();
});
I want to always be a selected option, currently shows only one option visible within select and other options that are blank.
what I need is exactly this but only with an option and always this option selected and without the repetition of selects of course.
Edit your question and put your controller please, just this I can’t help
– Jackson
@Jackson Edited question !
– Eduardo Krakhecke
OK @Eduardo, what’s the API answer?
– Jackson
@Jackson or Response is via JSON of an entity array
– Eduardo Krakhecke
@Jackson I reedited the question there.. maybe it got better to understand what I need.
– Eduardo Krakhecke
I understand what you want, can you pass me what comes from your HTTP Request call? What comes from http://localhost:8080/user/districts ?
– Jackson
I get a Json 
 Array;
{idDistrito: 3, nome: "Distrito de Taquari", codigoDne: "00002454", flagAtivo: 1, entidade: {…}, …}

{idDistrito: 45, nome: "testeee", codigoDne: "00000009", flagAtivo: null, entidade: 1, …}

{idDistrito: 46, nome: "salvando distrito", codigoDne: "000008", flagAtivo: null, entidade: 1, …}
– Eduardo Krakhecke
I answered the question with a plunker, I did the fixed JSON structure assuming what it would look like. Because JSON there is not complete
– Jackson