NG-表类型错误:不能设置为空值的属性“$ DATA”为空、属性、错误、类型

2023-09-13 03:06:34 作者:涐扪の噯纞

我使用的是NG-表显示来自API调用的信息,我喜欢上了的网站。

然而,网站上的例子使用的静态信息哪里,因为我需要让每一次新的API调用。当我不包括$ 范围。$腕表('GROUPBY',函数(值)功能,我缓行,以显示表头,初始呼叫。

  angular.module('myApp.controllers',['ngTable','ui.bootstrap','对话']).controller('HomeCtrl',函数($范围,$日志$ rootScope,$莫代尔,TimeService,EventServiceAPI,$过滤器,ngTableParams){    VAR基准=新的日期()调用setHours(0,0,0,0)。    $ scope.datum =基准;    VAR时间戳= Math.round(新的Date()的getTime()/ 1000);    VAR findAllEvents =功能(timestampdata){        EventServiceAPI.query({开始:timestampdata,结束:timestampdata + 3 * 24 * 60 * 60})$ promise.then(功能(数据){            // VAR数据= $过滤器('排序依据')(数据,'event.startHour');            $范围。$表(数据功能(){                $ scope.tableParams.reload();            });            $ scope.tableParams =新ngTableParams({                页面:1,//显示第一页                数:100 //每页计            },{                GROUPBY:函数(项目){                    回归开始vanaf'+ item.event.startHour +'UUR';                },                总:data.length,                的getData:函数($延迟,则params){                    VAR orderedData = params.sorting()?                            $滤波器('ORDERBY')(数据,'event.startHour'):                            数据;                    $ defer.resolve(orderedData.slice((params.page() -  1)* params.count(),params.page()* params.count()));                }            });            $范围。$腕表('GROUPBY',功能(价值){                $ scope.tableParams.settings()GROUPBY =价值。                的console.log('范围值',$ scope.groupby);                的console.log(观察值,this.last);                的console.log(新表,$ scope.tableParams);                $ scope.tableParams.reload();            });        })    };    findAllEvents(时间戳);    $ scope.getEarlier =功能(){        基准 -  =(24 * 60 * 60 * 1000);        $ scope.datum =基准;        VAR时间戳= Math.round(数据/ 1000);        的console.log(时间戳);        findAllEvents(时间戳);    };}); 

编辑:

我现在能够显示数据,但是组没有显示:

  VAR基准=新的日期()调用setHours(0,0,0,0)。    $ scope.datum =基准;    VAR时间戳= Math.round(新的Date()的getTime()/ 1000);    EventServiceAPI.query({开始:时间戳,结束:时间戳+ 3 * 24 * 60 * 60})$ promise.then(功能(数据){$ scope.data =数据; initlizeTable();});    VAR initlizeTable =功能(){        //表        $ scope.tableParams =新ngTableParams({            页面:1,//显示第一页            数:100 //每页计        },{            GROUPBY:函数(项目){                回归开始vanaf'+ $ scope.data.event.startHour +'UUR';            },            总计:$ scope.data.length,            的getData:函数($延迟,则params){                VAR数据= EventServiceAPI.query({开始:时间戳,结束:时间戳+ 3 * 24 * 60 * 60});                VAR orderedData = params.sorting()?                        $滤波器('ORDERBY')($ scope.data,'event.startHour'):                            $ scope.data;                        $ defer.resolve($ scope.data.slice((params.page() -  1)* params.count(),params.page()* params.count()));            } $范围:{$数据:$ scope.data}        });        $范围。$腕表('GROUPBY',功能(价值){            $ scope.tableParams.settings()GROUPBY =价值。            的console.log('范围值',$ scope.groupby);            的console.log(观察值,this.last);            的console.log(新表,$ scope.tableParams);            $ scope.tableParams.reload();        });        $范围。$表(数据,功能(价值){            $ scope.tableParams.settings()GROUPBY =价值。            的console.log('范围值',$ scope.groupby);            的console.log(观察值,this.last);            的console.log(新表,$ scope.tableParams);            $ scope.tableParams.reload();        });    } 

解决方案

我知道这是为时已晚,但我想更好地发表评论,这对于其他人谁寻求在同一问题上的答案。

我也有同样的问题,并设法通过遵循以下网址的例子来解决。

https://github.com/esvit/ng-table/blob/master/src/scripts/04-controller.js

我只是添加了以下code线到ngTableParams创建实例后,我的code。

  $ scope.params.settings()$范围= $范围; 
Android官方架构组件DataBinding Ex 双向绑定篇

I'm using ng-table to display information from an API call which I group like the example on the website.

However, the example on the website makes use of static information where as I need to make a new API call each time. When I don't include the $scope.$watch('groupby', function(value) function, I am amble to display the table for the first, initial call.

angular.module('myApp.controllers', ['ngTable','ui.bootstrap','dialogs'])
.controller('HomeCtrl', function($scope,$log, $rootScope, $modal, TimeService, EventServiceAPI, $filter, ngTableParams) {
    var datum = new Date().setHours(0,0,0,0);
    $scope.datum = datum;
    var timestamp = Math.round(new Date().getTime()/1000);


    var findAllEvents = function(timestampdata) {
        EventServiceAPI.query({start: timestampdata, end: timestampdata + 3*24*60*60}).$promise.then(function(data) {

            //var data = $filter('orderBy')(data, 'event.startHour');

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

            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 100          // count per page

            }, {
                groupBy: function(item) {
                    return 'Start vanaf ' + item.event.startHour + ' uur';
                },
                total: data.length,
                getData: function($defer, params) {
                    var orderedData = params.sorting() ?
                            $filter('orderBy')(data, 'event.startHour') :
                            data;

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

            $scope.$watch('groupby', function(value){
                $scope.tableParams.settings().groupBy = value;
                console.log('Scope Value', $scope.groupby);
                console.log('Watch value', this.last);
                console.log('new table',$scope.tableParams);
                $scope.tableParams.reload();
            });
        })
    };    

    findAllEvents(timestamp);

    $scope.getEarlier = function() {
        datum -= (24 * 60 * 60 * 1000);
        $scope.datum = datum;
        var timestamp = Math.round(datum/1000);
        console.log(timestamp);
        findAllEvents(timestamp);

    };
});

EDIT:

I am now able to display the data, however the groups are not displayed:

var datum = new Date().setHours(0,0,0,0);
    $scope.datum = datum;
    var timestamp = Math.round(new Date().getTime()/1000);

    EventServiceAPI.query({start: timestamp, end: timestamp + 3*24*60*60}).$promise.then(function(data) { $scope.data = data; initlizeTable(); });


    var initlizeTable = function() {
        // Table
        $scope.tableParams = new ngTableParams({
            page: 1,            // show first page
            count: 100          // count per page

        }, {
            groupBy: function(item) {
                return 'Start vanaf ' + $scope.data.event.startHour + ' uur';
            },
            total: $scope.data.length,
            getData: function($defer, params) {
                var data = EventServiceAPI.query({start: timestamp, end: timestamp + 3*24*60*60});
                var orderedData = params.sorting() ?
                        $filter('orderBy')($scope.data, 'event.startHour') :
                            $scope.data;

                        $defer.resolve($scope.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
            }, $scope: { $data: $scope.data }
        });

        $scope.$watch('groupby', function(value){
            $scope.tableParams.settings().groupBy = value;
            console.log('Scope Value', $scope.groupby);
            console.log('Watch value', this.last);
            console.log('new table',$scope.tableParams);
            $scope.tableParams.reload();
        });

        $scope.$watch('data', function(value){
            $scope.tableParams.settings().groupBy = value;
            console.log('Scope Value', $scope.groupby);
            console.log('Watch value', this.last);
            console.log('new table',$scope.tableParams);
            $scope.tableParams.reload();
        });

    }

解决方案

I know this is too late, but I thought better to comment on this for others who seeking for a answer for the same issue.

I also had the same issue and managed to fix by following the example in following URL.

https://github.com/esvit/ng-table/blob/master/src/scripts/04-controller.js

I just added the following code line into my code after 'ngTableParams' instance creation.

$scope.params.settings().$scope = $scope;