AngularJs数据长度返回零

时间:2015-10-05 03:55:04

标签: javascript angularjs

我有一个返回产品列表的函数,但是当我分配给一个数组时,该数组返回一个空内容:

  $scope.data = [];
        $scope.product = function(){
               Account.getProductList($scope.user)
                .then(function(response){
                    ngNotify.set('Product list ok!!', {
                    position: 'bottom',
                    duration: 2000
                });
                     $scope.data = response.data; ---> there is data
                     return $scope.data;

                })
                .catch(function(response){
                    console.log(response.data.messages);
                });

            };


        $scope.product();
        console.log($scope.data.length) ----> return []

数据应填充在角度ngTable上,如下所示:

$scope.tableParams = new ngTableParams({
        page: 1, // show first page
        count: 5, // count per page
        filter: {
            title: '' // initial filter,

        }
    }, {
        total: $scope.data.length, // length of data

        getData: function ($defer, params) {

            console.log($scope.data);
            var orderedData = params.filter() ? $filter('filter')($scope.data, params.filter()) : $scope.data;
            var orderedSort = params.sorting() ? $filter('orderBy')($scope.data, params.orderBy()) : $scope.data;
            $defer.resolve(orderedSort.slice((params.page() - 1) * params.count(), params.page() * params.count()));

            $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
            params.total(orderedData.length);

            // set total for recalc pagination
            $defer.resolve($scope.users);
        }


    });

我不知道这里出了什么问题。它曾经工作过,突然桌子现在都是空的。

谢谢!

0 个答案:

没有答案