1
I want to use two dropdowns in my HTML5 As I select in dropdown 1, it displays the respective data in dropdown 2, as in this link I searched the documentation of the angle that that you’ve come very close, but it hasn’t worked out yet. NOTE: Both dropdown values, are loaded from the api in php, and not placed "at hand" as in the link I passed above
HTML5
<form>
<label>Estabelecimento</label>
<select class="form-control" name="estabelecimento" ng-model="mesa.idestabelecimento" required="required" ng-change="getUnidade()" ng-options="c as c.nome for c in cia track by c.idestabelecimento">
<option value="">Selecione estabelecimento</option>
<option ng-repeat="c in cia" value="{{ c.idestabelecimento }}" required>{{ c.nome }}
</option>
</select>
<label>Unidade</label>
<select class="form-control" name="unidadeMesa" ng-model="mesa.unidade" required>
<option value="">Selecione unidade</option>
</select>
<label>Número da mesa</label>
<input class="form-control" type="text" name="numeroMesa" ng-model="mesa.numero" placeholder="Número da mesa">
<button class="btn btn-block btn-primary btnAdicionar" ng-click="adicionar(mesa)">Adicionar</button>
</form>
controller
app.controller("MesasCtrl", ['$scope', '$http', '$window', '$location', '$rootScope', function ($scope, $http, $window, $location, $rootScope) {
$rootScope.idestabelecimento = localStorage.getItem('idestabelecimento');
var buscarEstabelecimento = function(){
var opcao = 1; //Buscar estabelecimento
$http.get("http://localhost:8888/sistemas/Android/areaAdmin/api/admin_estabelecimento/mesa.php?opcao="+opcao).success(function(response){
$scope.cia = response;
})
}
buscarEstabelecimento();
$scope.getUnidade = function(){
$scope.selected = $scope.idestabelecimento;
var key = $scope.selected;
console.log("key :"+$scope.selected)
}
}]);
And regardless of the value I select in the first dropdown, the value on the console is always the same: "key :4"
You have two dropdown and you want one to load the other correct, but in your code you have repeat and options in the same dropdown... that’s what’s wrong.
– novic
Hello @Virgilionovic, both data loaded in the dropdowns comes from the backend... But I will try to use your example
– GustavoSevero
Opa @Gustavosevero, where are you
dropItens1
anddropItens2
if you load the information, only changes that the rest remains the same.– novic
Yes, I tried this, but it didn’t work kkkkkkk I did the following: $Scope.dropItens1 = [{'value': Answer.idestablishment}, {'text': Answer.name}];
– GustavoSevero
Can I generate an example could I understand with two Rest? dynamic data?
– novic