1
I have a mobile app where I have two select option
(districts and counties). What I intend is that when choosing a district appear only the counties that belong to that district.
How can I do that? I’ve tried filtering through ng-change
only that it is not appearing the name of the councils appears the blank list and by the console I can verify that filters.
View
<div ng-controller="FiltraEstabelecimentos">
<form ng-submit>
<div class="row">
<div class="col">
<label ng-controller="ListaDistritos" style="border-radius: 10px; margin: 0px 0px 10px 0px;" class="item item-input item-select">
<div class="input-label">
Distrito
</div>
<select ng-controller="ListaConcelhos" ng-model="distrito" ng-options="lista_distritos as lista_distritos.titulo for lista_distritos in distritos" ng-change="id_distrito()"></select>
</label>
<label ng-controller="ListaConcelhos" style="border-radius: 10px;" class="item item-input item-select">
<div class="input-label">
Concelho
</div>
<select ng-model="concelho" ng-options="lista_concelhos as lista_concelhos.titulo for lista_concelhos in concelhos"></select>
</label>
</div>
</div>
<div style="margin:0px 10px 0px 10px;">
<button type="submit" ng-click="filtra_estabelecimentos(input)" style="background-color: #CA5B60; border:#CA5B60; border-radius: 10px;" class="button button-block button-positive">
<i class="ion-search"></i> Pesquisar
</button>
</div>
</form>
</div>
PHP districts
function converte($term, $tp) {
if ($tp == "1") $palavra = strtr(ucwords(strtoupper($term)),"àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ","ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß");
elseif ($tp == "0") $palavra = strtr(ucwords(strtolower($term)),"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß","àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ");
return $palavra;
}
$distritos = array();
$sql = $conexao->prepare("SELECT * FROM distritos ORDER BY titulo");
$sql->execute();
$distritos = $sql->fetchAll(PDO::FETCH_ASSOC);
foreach ($distritos as $rows ) {
$distritos[] = array(
'titulo' => converte($rows['titulo'], 0),
);
}
echo json_encode($distritos);
PHP Concelhos
function converte($term, $tp) {
if ($tp == "1") $palavra = strtr(ucwords(strtoupper($term)),"àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ","ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß");
elseif ($tp == "0") $palavra = strtr(ucwords(strtolower($term)),"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß","àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ");
return $palavra;
}
$concelhos = array();
$sql = $conexao->prepare("SELECT * FROM concelhos WHERE id_mae = :distritos ORDER BY titulo");
$sql->bindParam(':distritos', $_GET['id_distrito'], PDO::PARAM_INT);
$sql->execute();
$row = $sql->fetchAll(PDO::FETCH_ASSOC);
foreach ($row as $rows ) {
$concelhos[] = array(
'titulo' => converte($rows['titulo'], 0),
);
}
echo json_encode($concelhos);
County and District Controller
.controller('ListaDistritos', function($scope, $http) {
$http.get("https://www.sabeonde.pt/api/api_distritos.php").success(function (data) {
$scope.distritos = data;
});
})
.controller('ListaConcelhos', function($scope, $http, $stateParams) {
$scope.id_distrito= function (){
$http.get("https://www.sabeonde.pt/api/api_concelhos.php?id_distrito="+$scope.distrito.id).success(function (data) {
$scope.concelhos = push(data);
});
};
})
Already tried to consult the councils in the change of the district combobox?
– Emir Marques
Is not missing the
where
hereSELECT * FROM concelhos ORDER BY titulo
, that would be it?– rray
No, and I don’t know how I can do if I publish an answer I’d appreciate how I could do ?
– César Sousa
Is not for two comments or just mine? xD
– rray
and for Emir Marques
– César Sousa
Emir Marques I made a change with ng-change I’ve already put the code above so don’t stop the councils when I select a district must be missing something
– César Sousa
See if it helps, http://stackoverflow.com/a/15688483/1342547
– rray
I tested but it didn’t work still the same
– César Sousa