无法阅读财产'然后'在MdDataTable中未定义

时间:2016-07-11 13:15:53

标签: javascript angularjs asynchronous get angular-material

我使用MdDataTable显示我想从服务器检索的一些数据。我想使用分页。 这是 angular 代码:

    $scope.paginatorCallback = function(page, pageSize){
        var offset = (page-1) * pageSize;

        MySrv.getData.get(
            {
                offset: offset,
                pageSize: pageSize
            }, function (data) {
                return {                  
                        results: data.list,
                        totalResultCount: data.totalResults
                    }
            }, function (error) {
               alert(error);
            }
        )
    }

这是 html 代码:

 <mdt-table
    paginated-rows="{isEnabled: true, rowsPerPageValues: [5,10,20,50]}"
    mdt-row-paginator="paginatorCallback(page, pageSize)"
    mdt-row-paginator-error-message="Error happened during loading nutritions."
    mdt-row="{
        'table-row-id-key': 'fields.item_id',
        'column-keys': [
            'fields.item_name',
            'fields.nf_calories',
            'fields.nf_total_fat',
            'fields.nf_total_carbohydrate',
            'fields.nf_protein',
            'fields.nf_sodium',
            'fields.nf_calcium_dv',
            'fields.nf_iron_dv'
        ],
    }">
    <mdt-header-row>
        <mdt-column align-rule="left">Dessert (100g serving)</mdt-column>
        <mdt-column align-rule="right">Calories</mdt-column>
        <mdt-column align-rule="right">Fat (g)</mdt-column>
        <mdt-column align-rule="right">Carbs (g)</mdt-column>
        <mdt-column align-rule="right">Protein (g)</mdt-column>
        <mdt-column align-rule="right">Sodium (mg)</mdt-column>
        <mdt-column align-rule="right">Calcium (%)</mdt-column>
        <mdt-column align-rule="right">Iron (%)</mdt-column>
    </mdt-header-row>
</mdt-table>

它调用服务器并正确检索数据(因此这不是服务器的问题),但我无法在html中看到任何数据,我在控制台中出现此错误:

angular.js:13708 TypeError: Cannot read property 'then' of undefined
at mdtAjaxPaginationHelper.fetchPage (http://localhost/vendor/mdDataTable/md-data-table.js:629:17)
at new mdtAjaxPaginationHelper (http://localhost/vendor/mdDataTable/md-data-table.js:586:18)
at Object.getInstance (http://localhost/vendor/mdDataTable/md-data-table.js:677:24)
at initTableStorageServiceAndBindMethods (http://localhost/vendor/mdDataTable/md-data-table.js:208:85)
at new mdtTableController (http://localhost/vendor/mdDataTable/md-data-table.js:197:17)
at Object.invoke (http://localhost/vendor/angular/angular.js:4709:19)
at $controllerInit (http://localhost/vendor/angular/angular.js:10234:34)
at nodeLinkFn (http://localhost/vendor/angular/angular.js:9147:34)
at http://localhost/vendor/angular/angular.js:9553:13
at processQueue (http://localhost/vendor/angular/angular.js:16170:28) undefined

0 个答案:

没有答案