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

Error: [$injector:unpr] Unknown provider: setPageProvider <- setPage

本文关键字:setPageProvider 程序 setPage injector unpr 未知 错误      更新时间:2023-09-26

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

这是我的控制器.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();
                }
            ]
        );
 }());

这是我的搜索.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>

我正在尝试为页面添加分页,以便我可以像在页面中一样在表格中看到结果。

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

在您的控制器'SearchController'中,您正在注入'setPage'$setPage。取出两个注射。

编辑:

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

我自己解决了这个问题。我不得不重新编辑控制器.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 [];
        }
    });