1
I have a JSON of states and cities as follows:
{
"estados": [
{
"sigla": "AC",
"nome": "Acre",
"cidades": [
"Acrelândia",
"Assis Brasil",
"Brasiléia",
"Bujari",
"Capixaba",
"Tarauacá",
"Xapuri"
]
},
{
"sigla": "AL",
"nome": "Alagoas",
"cidades": [
"Água Branca",
"Anadia",
"Arapiraca"
]
}
and continues this way for all states of Brazil.
What I’m unable to do is fill a < select > (combo) with all states, and after selecting the state fill another < select > listing all cities of this state.
What I’ve done so far is:
$scope.ListarEstados = function GetEstados(){
var listaEstados = estadosCidadesService.GetEstados();
listaEstados.then(function(response){
console.log(response.data);
$scope.ListEstados = response.data.estados.map(function(retAPI){
return{
UF: retAPI.sigla,
NOMEUF: retAPI.nome
};
});
});
};
o . html
<div class="form-group">
<label class="control-label">Estado</label>
<select ng-model="estadoscidades.ESTADO" class="form-control">
<option ng-repeat="e in ListEstados">{{e.UF}}</option>
</select>
</div>
Now the city do not know how to do according to the selected state.
Thank you!
Thank you. It would be like selecting the state instead of charging to the first city, getting written <<choose the city>>?
– Core
@Core made another example!
– novic