更新 angularjs 中的 table 内容

Update table content in angularjs

我在 ng-click 后无法更新 table 的数据。在我 select 组合框(下拉列表)上的项目之后,它不会更新 table 内容。这是我的组合框:

<!-- 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>

Table 与 ng-repeat:

<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-repeat="servico in listaDeServicos track by $index"

是你数据返回有重复值? 尝试一下上面办法,增加 track by $index

(English: Is your data returned with duplicate values? Try the above approach to add)