1

I am working on an project and need to modify some code to resolve an error
directive:

(function () {
    'use strict';

    angular.module('myApp').directive("myDirective", function ($filter) {
        return {
            // code
        };
    });
})();

This throws an error with the minified version only. I am using angular 1.5.9

I think I need to define $filter somewhere.

Babulaas
  • 761
  • 3
  • 13
  • 47
  • I'd like to refer you to this: [Dependency Injection](https://docs.angularjs.org/guide/di#dependency-annotation) – Giovani Vercauteren Mar 30 '17 at 09:49
  • Possible duplicate of ["Uncaught Error: \[$injector:unpr\]" with angular after deployment](http://stackoverflow.com/questions/19671962/uncaught-error-injectorunpr-with-angular-after-deployment) – tanmay Mar 30 '17 at 09:49

2 Answers2

3

I assume you have the app already defined somewhere.

You seem to have not injected $filter, try this instead:

(function () {
  'use strict';

  angular.module('myApp').directive("myDirective", ["$filter", function ($filter) {
    return {
      // code
    };
  }]);
})();
rrd
  • 5,789
  • 3
  • 28
  • 36
1

When you are using minified version of angular you need to inject the dependencies as a separate string array. Otherwise, dependency injector unable to identify which is which

(function () {
    'use strict';

    angular.module('myApp')
      .directive("myDirective",myDirective);

    myDirective.$inject = ['$filter'];

    function myDirective($filter) {
        return {
            // code
        };
    }

})();
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80