2016-03-07 82 views
0

我正在嘗試使用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> 

我想添加分頁的頁面,這樣我可以看到導致在一個頁面中的表格。

+0

你注入了'setPage'服務嗎? –

+0

對不起@JyotiPrakash你是什麼意思注入setpage?我是新的angularjs框架 – anonymous5671

+0

angular.module('appName',['setPage']); –

回答

0

您正在注射setPage您的SearchController,但服務/工廠不存在。

+0

我可以知道我該如何解決它?我是angularjs框架的新手。我正在關注問題中發佈的網站鏈接中的教程。 – anonymous5671

0

在您的控制器'SearchController'中,您正在注入'setPage'$setPage。刪除兩次注射。

編輯:

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

其仍然不能正常工作 – anonymous5671

+0

但現在仍然是一樣的錯誤? – ddepablo

+0

是的,實際上是一樣 – anonymous5671

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 []; 
     } 
    }); 
相關問題