nofear87
nofear87

Reputation: 869

Filter in separate file throws unknown provider

I generate the following file (slice.js):

function slice ($scope) {
   return function(arr, start, end) {
       return arr.slice(start, end)
   }
}

angular
   .module('loop')
   .filter('slice', slice)

in my directive template I call the filter

div(ng-repeat="(periodKey,period) in periods | slice:start:end").col

and I get the unnow provider error.

But when i define the filter in my app.js like this

app.filter('slice', function() {
   return function(arr, start, end) {
      return arr.slice(start, end);
   };
});

There is no error and it works fine. Can you help me to solve the problem please?

Thanks!

Upvotes: 0

Views: 165

Answers (1)

New Dev
New Dev

Reputation: 49620

Remove $scope from the parameters of your slice function.

Angular expects to inject a service there, and there is no service provider for the service called $scope (obviously). Read here about dependency injection in Angular

Upvotes: 1

Related Questions