w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Angular pagination using bootstrap. Slice of undefined. Remote data

The difference between your code and the plunker is the contents of the success function.

Try modifying your code like so:

.state('home', {
    url: '/',
    templateUrl: 'partials/galerija.html',
    controller: function($scope, Picture) {
        $scope.filteredPictures = [], $scope.currentPage = 1,
$scope.numPerPage = 18, $scope.maxSize = 5;


        Picture.get('').success(function(data) {
            $scope.pictures = data;

            $scope.numPages = function() {
                return Math.ceil($scope.pictures.length /
$scope.numPerPage);
            };

            $scope.$watch('currentPage + numPerPage', function() {
                var begin = (($scope.currentPage - 1) * $scope.numPerPage),
                    end = begin + $scope.numPerPage;

                $scope.filteredPictures = $scope.pictures.slice(begin,
end);
            });

        });
    }
});

You'll notice that the .slice() call is now occurring synchronously after $scope.pictures = data; occurs.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.