简体   繁体   English

Angular.js-providerInjector错误

[英]Angular.js - error with providerInjector

I have a problem with providers in angular, I get this error: 我在角度提供程序时遇到问题,出现此错误:

Row 2696: Error: Unknown provider: a 第2696行:错误:未知提供程序:

Using unminified angular v 1.06, Row 2696: 使用未缩小的角度v 1.06,第2696行:

providerInjector = createInternalInjector(providerCache, function() {
    throw Error("Unknown provider: " + path.join(' <- '));
}),

This is the code: 这是代码:

var myApp = angular.module('myApp', [], function ($interpolateProvider) {
    $interpolateProvider.startSymbol('{[{');
    $interpolateProvider.endSymbol('}]}');
});

myApp.directive('buttonsRadio', function() {      
[...]
});


myApp.controller('MainController', function MainController ($scope) {
[...]
})

Any ideas? 有任何想法吗?

Edit: Added error message: 编辑:添加了错误消息:

Error: Unknown provider: aProvider <- a
createInjector/providerInjector<@/libs/angular.js:2696
getService@/libs/angular.js:2824
createInjector/instanceCache.$injector<@/libs/angular.js:2701
getService@/libs/angular.js:2824
invoke@/libs/angular.js:2842
instantiate@/libs/angular.js:2874
@/libs/angular.js:4759
applyDirectivesToNode/nodeLinkFn/<@/libs/angular.js:4338
forEach@/libs/angular.js:138
nodeLinkFn@/libs/angular.js:4323
compositeLinkFn@/libs/angular.js:3969
compositeLinkFn@/libs/angular.js:3972
nodeLinkFn@/libs/angular.js:4354
compositeLinkFn@/libs/angular.js:3969
publicLinkFn@/libs/angular.js:3874
bootstrap/resumeBootstrapInternal/</<@/libs/angular.js:963
Scope.prototype.$eval@/libs/angular.js:8011
Scope.prototype.$apply@/libs/angular.js:8091
bootstrap/resumeBootstrapInternal/<@/libs/angular.js:961
invoke@/libs/angular.js:2857
bootstrap/resumeBootstrapInternal@/libs/angular.js:960
bootstrap@/libs/angular.js:973
angularInit@/libs/angular.js:934
@/libs/angular.js:14756
f.Callbacks/n@http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2
f.Callbacks/o.fireWith@http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2
.ready@http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2
B@http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2

/libs/angular.js
Line 5704

Before running uglify or any other ofuscator/compression algorithm, you should run the grunt task ng-annotate which adds the dependencies as strings for you as an injectable array, this makes your code a lot cleaner as the injectable annotaion can be added automatically as a build step rather than having to manually code it. 运行前uglify或任何其他ofuscator /压缩算法,你应该运行繁重的任务ng-annotate这增加的依赖性为字符串你作为一个注射阵列,这使得你的代码有很多清洁的注射annotaion可以自动为添加构建步骤,而不必手动对其进行编码。

myApp.controller('MainController', function MainController ($scope) {
[...]
})

Becomes: 成为:

myApp.controller('MainController', ['$scope', function MainController ($scope) {
[...]
}])

Take a look at: https://github.com/olov/ng-annotate 看看: https//github.com/olov/ng-annotate

Update: ng-min AngularJS Pre-minifier deprecated –> use ng-annotate 更新: 建议使用 ng-min AngularJS预minifier –>使用ng-annotate

I assume you're using some kind of javascript obufuscator (Clousure, SquishIt, UglifyJS etc). 我假设您使用的是某种JavaScript混淆器(Clousure,SquashIt,UglifyJS等)。

In this case you need to specify dependencies in such way: 在这种情况下,您需要通过以下方式指定依赖项:

var myApp = angular.module('myApp', [], ['$interpolateProvider',function ($interpolateProvider) {
    $interpolateProvider.startSymbol('{[{');
    $interpolateProvider.endSymbol('}]}');
}]);

myApp.directive('buttonsRadio', function() {      
[...]
});


myApp.controller('MainController',['$scope', function MainController ($scope) {
[...]
}])

Note to specify dependenices for dependency injection - instead of passing function, you need to specify array with list of strings with names of objects to inject into parameters and the function itself. 请注意为依赖项注入指定依赖项-而不是传递函数,您需要指定带有字符串列表的数组,该字符串列表包含要注入参数和函数本身的对象名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM