0
我無法在ng-click後更新表格的數據。在我選擇一個組合框上的項目(下拉列表)後,它不會更新表格內容。這裏是我的組合框:在angularjs中更新表格內容
<!-- Combobox -->
<div class="row">
<div class="dropdown" ng-controller="StabPageCtrl">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdown_stabs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Estabelecimentos
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdown_stabs" >
<li>
<a ng-repeat="estab in stablishmentList" ng-click="passdata(stab.stabId)">
{{estab.nomeEstab}}
</a>
</li>
</ul>
</div>
</div>
表與NG-重複:
<table class="table table-hover" ng-controller="StabPageCtrl">
<thead>
<tr>
<th>Serviço</th>
<th>Descrição Serviço</th>
<th>Valor/Valor hora</th>
<th>Status</th>
</tr>
</thead>
<tbody ng-repeat="servico in listaDeServicos">
<tr>
<td>{{servico.nomeServico}}</td>
<td>{{servico.descServico}}</td>
<td>Valor: R${{servico.precoServico}} - Valor/Hora: R${{servico.precoHoraServico}}</td>
<td>VER FLAG DEPOIS</td>
<li ng-hide="listaDeServicos.length > 0">Lista vazia.</li>
</tr>
</tbody>
</table>
控制器:
angular.module('yapp').controller('StabPageCtrl', function($scope, $state, ListServicoService, ListStabService) {
/**
* Controller do dropdown que escolhe o estabelecimento
*/
$scope.passdata = function(id){
console.log("ctrl: " + id);
ListServicoService.listarServicos(id).then(function(dados){
$scope.listaDeServicos = dados;
console.log($scope.listaDeServicos);
});
}
/**
* Controller que lista os estabelecimentos
*/
ListStabService.listAllStabs.then(function(estabs){
$scope.stablishmentList = estabs;
}); });
服務
angular.module('yapp')
.service('ListServicoService', function($http){
return{
listarServicos : function (id){
console.log("serv: " + id);
return $http.get('http://localhost:3854/listarServicosByEstab/' + id).then(function(response){
return response.data;
});
}
}});
爲什麼你有'NG-控制器=「StabPageCtrl」'發起兩次在表中和組合框? – Weijian