7

私は ng-table の最初の例 ( http://bazalt-cms.com/ng-table/example/1 ) に従っています。

tableParams 以外はすべて動作するようです。コントローラーに含めるとすぐに、ページに何も表示されません。

例と私のコードの違いは、json サービスからデータをロードすることです。

angular.module('mean.cars').controller('CarsController', ['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {
    $scope.global = Global;
    var data = Cars.query();

$scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10           // count per page
}, {
    total: data.length, // length of data
    getData: function($defer, params) {
        $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
});

Cars.query(); うまく動作しています(テスト済み)。それで、私は何が欠けていますか?次の行に「未定義は関数が発生していません」という JavaScript エラーがあります。

$scope.tableParams = new ngTableParams({
4

4 に答える 4

5

ngTableParams がどこから来たのかわかりませんが、注入していません:

['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {

それは次のようになります。

['$scope', '$stateParams', '$location', 'Global', 'Cars', 'ngTableParams',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {

またはこのように:

['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars) {    
于 2014-03-28T12:41:49.323 に答える
-2

getData でサービスを実行する

$scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10           // count per page
}, {
    total: data.length, // length of data
    getData: function($defer, params) {
        data = Cars.query();
        $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
});
于 2015-04-25T00:06:17.750 に答える