2016-08-16 4 views
0

У меня есть эта ошибка, и я не понимаю, почему именноuniqueFilter ошибка в угловых

.angular.min.js:117 Error: [$injector:unpr] http://errors.angularjs.org/1.5.5/ $injector/unpr?p0=uniqueFilterProvider%20%3C-%20uniqueFilter at Error (native).

может кто-нибудь пожалуйста, просмотрите мой код?

HTML:

<select ng-model="selectedcategory" ng-options = "item.category_name for item in stockReport | 
unique:'category_name'"> 
<option value="">בחר קטגוריה</option> 
</select>  
<tr ng-repeat = "item in stockReport" ng-show = "item.category_name == selectedcategory" 
ng-init = "setTotals(item)"</> 

Контроллер:

"use strict"; 
angular.module('dataSystem').controller('reportsCtrl', function ($scope, $route, $location, $http) { 
    $http({method:'GET', url:'api/reports-tab/stock-report.php/'}) 
     .then(function(response) { 
     var arr = JSON.parse(JSON.parse(response.data)); 
     $scope.stockReport = arr; 
     })  
     // This will log you the error code and trace, if there is an error.  
      .catch(function(err) { 
      console.log('err', err) 
      })  
      $scope.total = 0; 
      $scope.setTotals = function(item){ 
       if (item){   
        $scope.total += parseInt(item.quantity); 
        return $scope.total;   
       }   
      }  
    }); 

PHP запрос:

$query=" SELECT `category_name`, `refer_category_id`, `stock_id`,`product_name`,`description`,`quantity` 
    from stock, stock_category WHERE `category_id` = `refer_category_id` group by `stock_id` "; 
+0

Вы загрузили уникальную библиотеку и ввели ее? https://github.com/angular-ui/angular-ui-OLDREPO/blob/master/modules/filters/unique/unique.js – AranS

ответ

1

Ответ был определить новый фильтр:

angular.module('dataSystem').filter('unique', function() { 
    return function(collection, keyname) { 
     var output = [], 
     keys = []; 

     angular.forEach(collection, function(item) { 
      var key = item[keyname]; 
      if(keys.indexOf(key) === -1) { 
       keys.push(key); 
       output.push(item); 
      } 
     }); 

     return output; 
     }; 
    }); 
+0

отлично работает для меня! – tanyaa

Смежные вопросы