问题
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.
回答1:
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
};
}]);
})();
回答2:
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
};
}
})();
来源:https://stackoverflow.com/questions/43114108/angular-directive-throws-error-injectorunpr