2014-09-30 56 views
2

我想使用ng-table,但是與ngTableParams卡在一起。我不斷收到錯誤:'undefined'不是構造函數(評估'ngTableParams')

[Error] Error: 'undefined' is not a constructor (evaluating 'new ngTableParams') 

錯誤,無論我嘗試什麼東西。

當前的代碼看起來像

$scope.tableParams = new ngTableParams({ 
    page: 1, 
    count: 200, 
    sorting: { 
     name: 'asc' 
    } 
}, { 
    groupBy: 'area', 
    total: TheData.length, 
    getData: function($defer, params) { 
     // use build-in angular filter 
     var orderedData = params.sorting() ? $filter('orderBy')(TheData, params.orderBy()) : TheData; 
     $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); 
    } 
}); 

的應用程序和控制器與ngTable和ngTableParams調用:

angular.module('MegaList', ['ui.bootstrap', 'ngTable']); 
angular.module('MegaList').controller('DisplayMegaList', ['$scope', 'ngTableParams', function($scope, $http, ngTableParams) { 
    ... 
} 

我想我已經嘗試了所有的辦法來撰寫'ngTable''ngTableParams'ngTableParams關鍵字放在一起,但它仍然不起作用。

那我該怎麼試試?

回答

3

這是因爲您缺少參數。以及

angular.module('MegaList') 
     .controller('DisplayMegaList', ['$scope', '$http', 'ngTableParams', function($scope, $http, ngTableParams) 
+2

)事實上,訂單('scope','ngTableParams',function($ scope,ngTableParams,$ http){}]' – 2015-05-23 07:03:43

-1

它看起來像你在不同的模塊上創建控制器。嘗試使用MegaList.controller(...)而不是FloristList.controller(...)

+0

這是不是這樣的,我只是輸入了錯誤的密碼。模塊都是一樣的。在這個問題的描述部分,我重寫了代碼以避免任何不必要的變量,所以現在很明顯,一切都發生在一個模塊中。 – 2014-10-01 12:44:49

+0

它看起來像現在你有不同數量的參數。 ('MegaList')。controller('DisplayMegaList',['$ scope','$ http','ngTableParams',function($ scope,$ http,ngTableParams)' – 2014-10-01 12:53:49

-1

我有一個類似的問題,僅僅複製beforeEach從這個樣本幫我都要匹配: https://docs.angularjs.org/guide/unit-testing

beforeEach(inject(function(_$controller_){ 
    // The injector unwraps the underscores (_) from around the parameter names when matching 
    $controller = _$controller_; 
})); 
相關問題