使用ui.router进行ngTable

时间:2016-08-03 17:00:52

标签: javascript angularjs ngtable

我在创建ngTable时尝试拆分工厂和控制器时出现此错误。

angular.js:12332 Error: [$injector:unpr] Unknown provider: ngTableParamsProvider <- ngTableParams <- SCODataCtrl
http://errors.angularjs.org/1.4.2/$injector/unpr?p0=ngTableParamsProvider%20%3C-%20ngTableParams%20%3C-%20SCODataCtrl
    at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:68:12
    at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:4264:19
    at Object.getService [as get] (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:4411:39)
    at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:4269:45
    at getService (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:4411:39)
    at Object.invoke (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:4443:13)
    at extend.instance (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:9001:34)
    at nodeLinkFn (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:8111:36)
    at compositeLinkFn (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:7543:13)
    at publicLinkFn (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js:7418:30) <div ui-view="" class="ng-scope">

我无法弄清楚哪个部分出错了,因为我已将其包含在我的主js文件,控制器和工厂文件中。以下是适用的文件。

app.js

var myApp=angular.module("myApp", ['ui.router', 'ngTable']);

myApp.config(function($stateProvider, $urlRouterProvider){ // part of the ui library downloaded
    $stateProvider
        .state("settings.SCOData", { // child templtes to settings layout
            url: "/SCOData",
            templateUrl: "templates/SCOData.html", //this is in the root of the www. it all depends on the folders
            controller: 'SCODataCtrl'
        })
        $urlRouterProvider.otherwise("/settings");
});

注意:为方便起见,我删除了其他状态

SCODataCtrl.js

var myApp=angular.module("myApp");

    myApp.controller('SCODataCtrl', function($scope, $filter, $timeout, ngTableParams, ScoData) {
        // $scope is variables and arguments accessable to template (we're providing them)

        $scope.tableParams = new scoDataTable({
            page:1,
            count:10
        }, {
            total: $scope.users.length,
            getData: function($defer, params) {
                callServer.getData($defer,params,$scope.filter).then(function(){
                $scope.tableParams.settings({data:data});
            });
        }
        });

        $scope.$watch("filter.$", function () {
            $scope.tableParams.reload();
        });
    });

scoData.js

var myApp = angular.module("myApp");

    myApp.factory('ScoData', function($http, $q, $timeout){
        var service = {};

        service.callServer = function(){
            var deferred = $q.defer();
            $http({
                url:'php/getScoData.php'
                }).success(function(data){
                    $scope.data = $scope.users.slice(params.page() * params.count(), params.page * params.count());
                    $defer.resolve($scope.data);
                }).error(function(){
                    deferred.reject("No connection could be estabishled.")
            })
            return deferred.promise
        }
        return service;
    });

感谢您的帮助。如果需要其他任何东西来确定问题,请告诉我。

1 个答案:

答案 0 :(得分:0)

我通过将['ScoData',function ...]添加到我的控制器来修复它。

 myApp.controller('SCODataCtrl', ['ScoData', function($scope, $filter, $timeout, ngTableParams, ScoData) {}]);