2

我想了解为什么这段代码有效,但是当它运行时,我收到一条消息:app.controller(...) 不是一个函数,我该如何修复它?

  <script>
    var app = angular.module('filtraPedido', []);
    app.controller('listdata',function($scope, $http){


        $scope.pedidos = [{'pedidoData':'15/01/2016 17:03:10','pedidoId':'603530313428-01','pedidoStatus':'Pagamento Pendente','pedidoValor':'3398','produtoId':'29','produtoNome':'Garrafa Personalizada (350 ml)','produtoPreco':'1400','produtoPagamento':'Boleto Bancário','produtoSeller':'Seller Name','hostname':'seller1','pedidoEstado':'RJ','pedidoCidade':'Rio de Janeiro','pedidoBairro':'Pechincha','utmCampaing': '','utmMedium': '','utmSource': ''}];

        $scope.sort = function(keyname){
            $scope.sortKey = keyname;   //set the sortKey to the param passed
            $scope.reverse = !$scope.reverse; //if true make it false and vice versa
        }

    })();

  </script>

https://jsfiddle.net/andremiani/kac912ep/

4

2 回答 2

3

您正在尝试通过使用立即将您的 app.controller 注册作为函数执行

app.controller('listdata',function($scope, $http){
    ...
})();

这是不正确的,因为 app.controller 不是可以调用的函数。只需删除关闭参数。

app.controller('listdata',function($scope, $http){
    ...
});
于 2016-01-25T18:14:28.783 回答
0

这是更新的小提琴。https://jsfiddle.net/kac912ep/3/

刚刚()从第 94 行删除。

于 2016-01-25T18:17:48.523 回答