0

我将使用 ngTable,我是 AngularJS 的新手,我不知道问题出在哪里:-(

我的错误:

TypeError: undefined is not a function
    at Object.InputController.$scope.tableParams.ngTableParams.getData 

我的代码:

  angular.module("kasseev", ["firebase","ngTable"]);
  function InputController($scope, $firebase, ngTableParams) {

        var BaseRef = "https://xxxxxxx/";
        var FBBaseRef = new Firebase(BaseRef);
        var KontenRef = FBBaseRef.child("/posten/konto");
        $scope.getKonten = $firebase(KontenRef);
         $scope.tableParams = new ngTableParams({
            page: 1,            // show first page
            count: 10           // count per page
        }, {
        total: $scope.getKonten.length, // length of data
        getData: function($defer, params) {
            $defer.resolve($scope.getKonten.slice((params.page() - 1) * params.count(), params.page() * params.count()));
        }
        });    
4

1 回答 1

0

有几个选项 - 可以在这里找到一个http://plnkr.co/edit/LCBWeu?p=info - 使用 ngTables reload fn 和 firebase on 'child_added' 方法。或者您可以将请求放在 angularjs 服务/工厂中并在 ngtable getData 方法中使用 - 例如

var data = [];


$scope.tableParams = new ngTableParams ( {
        page : 1,
        count : 10,
        filter : {
        },
        sorting : {
            name : 'asc' // initial filter
        }
    }, {
getData: function ($defer, params) {
kontenService.getKonten ( 'param', function ( res ) {
angular.forEach ( res, function (r) {
data.push (r);

$scope.konten = data;  // not necessary could simply be res
var filteredData = params.filter () ?
                    $filter ( 'filter' ) ( data, params.filter () ) :
                    data;
var orderedData = params.sorting () ?
                  $filter ( 'orderBy' ) ( filteredData, params.orderBy () ) :
                  data;

params.total ( orderedData.length );
$defer.resolve ( orderedData.slice ( (params.page () - 1) * params.count (),
                        params.page () * params.count () ) );
});
}

选择是你的。塔海尔

于 2014-06-24T16:49:04.950 回答