错误:[$ injector:unpr]未知提供者:setPageProvider< - setPage

时间:2016-03-07 07:26:43

标签: javascript php angularjs

我正在尝试使用angularjs框架为我的页面创建一个分页。目前,我收到Error: [$injector:unpr] Unknown provider: setPageProvider <- setPage的错误。我尝试改变代码的排列,但它仍然是相同的。我试图按照this website中的教程进行操作但不起作用。我能否知道解决这个问题的方法?提前谢谢。

这是我的controller.js代码:

(function () {

angular.module('myApp', ['MovieApp']).
    filter('startFrom', function() {
        return function(input, start) {
            if(input) {
                start = +start; //parse to int
                return input.slice(start);
            }
            return [];
        }
    }
    );

"use strict";
angular.module('MovieApp').
    controller('SearchController', 
            [  
                '$scope', 
                'dataService', 
                '$location',
                '$routeParams',
                '$timeout',
                'setPage',
                '$filter',

                function ($scope, dataService, $location, $routeParams, $timeout, $setPage, $filter){
                    $scope.searchMovies = [ ];
                    $scope.searchCount = 0;

                    var getSearchResult = function () {
                        dataService.getSearchResult().then(
                            function (response) {
                                $scope.searchCount = response.rowCount + ' movies';
                                $scope.searchMovies = response.data;
                                $scope.showSuccessMessage = true;
                                $scope.successMessage = "All movie Success";

                                $scope.currentPage = 1; //current page
                                $scope.entryLimit = 5; //max no of items to display in a page
                                $scope.filteredItems = $scope.searchMovies.length; //Initially for no filter
                                $scope.totalItems = $scope.searchMovies.length;
                            },
                            function (err){
                                $scope.status = 'Unable to load data ' + err;
                            }
                        );  // end of getStudents().then
                    };

                    $scope.setPage = function(pageNo) {
                        $scope.currentPage = pageNo;
                    };

                    $scope.filter = function() {
                        $timeout(function() {
                            $scope.filteredItems = $scope.filtered.length;
                        }, 10);
                    };

                    getSearchResult();

                }
            ]
        );

 }());

这是我的search.html代码:

<div>

<label>Search: <input ng-model="searchMovie" ng-change="filter()"></label><br><br><br><br>
</div>
<div ng-show="filteredItems > 0">
    <table class="table table-hover table-bordered">
        <thead>

        </thead>
        <tbody>
            <tr ng-repeat="searchmovie in filtered = (searchMovies | filter:searchMovie) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

            </tr>   
        </tbody>
    </table>
</div>

<div ng-show="filteredItems > 0">
    <div pagination="" page="currentPage" on-select-page="setPage(page)" 
    boundary-links="true" total-items="filteredItems" items-per-page="entryLimit" 
    previous-text="&laquo;" next-text="&raquo;">
    </div>
</div>

我正在尝试为页面添加分页,以便我可以在页面中查看结果。

3 个答案:

答案 0 :(得分:0)

您在setPage注入了SearchController,但服务/工厂并不存在。

答案 1 :(得分:0)

在您的控制器'SearchController'中,您正在注射'setPage'$setPage。取下两次注射。

修改

angular.module('MovieApp')
    .controller('SearchController', 
        ['$scope', 'dataService', '$location', '$routeParams', '$timeout', '$filter'
        , function ($scope, dataService, $location, $routeParams, $timeout, $filter){
            // Some code..
    }]);

答案 2 :(得分:0)

我自己解决了这个问题。我不得不在controller.js文件中重新编写模块代码。这是它的解决方案

var app = angular.module('MovieApp');
    app.filter('startFrom', function() {
        return function(input, start) {
            if(input) {
                start = +start; //parse to int
                return input.slice(start);
            }
            return [];
        }
    });