I want to use two dropdowns in my HTML5 Depending on what I select in dropdown 1, it displays its data in dropdown 2, as in that link . I looked up the documentation for the angled this that came very close, but still did not work. NOTE: Both dropdown values are loaded from api in php, not placed "by hand" as in the above link
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 in the console is always the same: "key: 4"