我在文件中添加了一个过滤器,现在我得到了喷射器错误,我们都非常喜欢。我正在尝试对其进行故障排除,我认为这可能与注射顺序有关。在注入它们之前,如何声明提供者/服务/等必须编译的顺序......
HTML:
<script src="js/app.js"></script>
<script src="js/directives/jokesDirective.js"></script>
<script src="js/filters/jokeFilter.js"></script>
<script src="js/providers/jokeService.js"></script>
<script src="js/controllers/mainController.js"></script>
app.js:
angular.module('jsekoApp', [ 'ui', 'ngRoute', 'ngSlider'])
.config( ... );
mainController.js:
angular.module('jsekoApp')
.controller('MainController', [ '$scope', 'JokeFilter', 'JokeService', function MainController($scope, JokeFilter, JokeService) {
...
}]);
JokeService工作正常 jokeFilter正在抛出错误 - jokeFilter.js:
angular.module('jsekoApp')
.filter('JokeFilter', [ '$scope', function JokeFilter($scope) {
...
}]);
在主控制器中,我在服务之前声明过滤器,因为服务需要过滤器。我认为这是正确的。我还在服务之前声明了HTML中的过滤器,并在angular和其他类似的依赖项之后声明..
完全错误:
Error: [$injector:unpr] Unknown provider: JokeFilterProvider <- JokeFilter
http://errors.angularjs.org/1.2.17/$injector/unpr?p0=JokeFilterProvider%20%3C-%20JokeFilter
at http://127.0.0.1:9000/bower_components/angular/angular.js:78:12
at http://127.0.0.1:9000/bower_components/angular/angular.js:3735:19
at Object.getService [as get] (http://127.0.0.1:9000/bower_components/angular/angular.js:3862:39)
at http://127.0.0.1:9000/bower_components/angular/angular.js:3740:45
at getService (http://127.0.0.1:9000/bower_components/angular/angular.js:3862:39)
at invoke (http://127.0.0.1:9000/bower_components/angular/angular.js:3889:13)
at Object.instantiate (http://127.0.0.1:9000/bower_components/angular/angular.js:3910:23)
at http://127.0.0.1:9000/bower_components/angular/angular.js:7164:28
at link (http://127.0.0.1:9000/bower_components/angular-route/angular-route.js:913:26)
at nodeLinkFn (http://127.0.0.1:9000/bower_components/angular/angular.js:6607:13) <div class="container-fluid ng-scope" ng-view=""> angular.js:9899
(anonymous function) angular.js:9899
(anonymous function) angular.js:7246
nodeLinkFn angular.js:6610
compositeLinkFn angular.js:6011
publicLinkFn angular.js:5916
boundTranscludeFn angular.js:6030
controllersBoundTransclude angular.js:6628
update angular-route.js:871
Scope.$broadcast angular.js:12797
(anonymous function) angular-route.js:552
wrappedCallback angular.js:11408
wrappedCallback angular.js:11408
(anonymous function) angular.js:11494
Scope.$eval angular.js:12518
Scope.$digest angular.js:12330
Scope.$apply angular.js:12622
done angular.js:8234
completeRequest angular.js:8439
xhr.onreadystatechange
答案 0 :(得分:2)
您遇到的问题是您正在尝试直接注入过滤器。请在此处查看解决方案:How to use a filter in a controller?
基本上,您无法直接注入过滤器本身,需要使用$filter
。
您可以在此处找到更多信息:https://docs.angularjs.org/api/ng/service/$filter