2017-03-06 160 views
0

下面的代碼片段與角度1.4.2完美協作,但是在將角度js庫升級到1.6.2之後。在角度js中使用自定義過濾器1.6.2

我搜索了遷移/升級文檔..等等。沒有找到解決方案。

HTML代碼:我的定製表的

<input ng-model="query" type="text" name="js_filter" > 

部分,tbItems.rows將包含在一個陣列/對象格式

<tr ng-repeat-start="datarow in resultItems = (tbItems.rows | filter:magikFilterQuery) " > 

JavaScript代碼段的一些數據:之後

myControllers.controller('myContrBasic', ['$scope', '$http', 
    function ($scope, $http) { 

    $scope.magikFilterQuery = function (item) { 
     var term; 
     var part; 
     if (angular.isUndefined($scope.query) === false) { 
      if ($scope.matchcase === true) { 
      term = item.data[3]; 
      part = $scope.query; 
      } 
      else { 
      term = angular.lowercase(item.data[3]); 
      part = angular.lowercase($scope.query); 
      } 
      if (term.indexOf(part) === -1) { 
      return false; 
      } 
      else { 
      return true; 
      } 
     } 
     else { 
      return true; 
     } 
     }; 

錯誤升級角度js:

angular.js:14362 Error: [$injector:unpr] http://errors.angularjs.org/1.6.2/$injector/unpr?p0=magikFilterQueryFilterProvider%20%3C-%20magikFilterQueryFilter 
    at http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:6:425 
    at http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:44:374 
    at Object.d [as get] (http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:42:92) 
    at http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:44:436 
    at Object.d [as get] (http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:42:92) 
    at http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:163:474 
    at U (http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:125:13) 
    at http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:123:123 
    at q (http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:7:351) 
    at U (http://localhost/site82/folder/js/angular162/angular.min.js?v=8.2.6:123:102) <!-- ngRepeat: datarow in (tbItems.rows | magikFilterQuery) as resultItems --> 
+0

請注資$過濾器,控制器,然後嘗試 – Jenny

+0

沒有運氣,得到同樣的錯誤 – rjD

+0

或者我已經看到了'.filter()函數在一些網站上使用..我可以使用...在這種情況下 – rjD

回答

1

您需要定義一個過濾器的功能magikFilterQuery像

angular.module('myApp').filter('magikFilterQuery', function() { 
    return function(item) { 
    var term; 
    var part; 
    if (angular.isUndefined($scope.query) === false) { 
     if ($scope.matchcase === true) { 
     term = item.data[3]; 
     part = $scope.query; 
     } 
     else { 
     term = angular.lowercase(item.data[3]); 
     part = angular.lowercase($scope.query); 
     } 
     if (term.indexOf(part) === -1) { 
     return false; 
     } 
     else { 
     return true; 
     } 
    } 
    else { 
     return true; 
    } 
    } 
}); 
+0

using this am getting the entire object在'item'中,我將不得不重新遍歷它 – rjD

+0

好吧,我想出了一個解決方案,我編輯了上面的代碼片段。 – rjD