我对提供者有一个问题,我得到了这个错误:
第2696行:错误:未知提供者:a
使用无限制角v 1.06,第2696行:
providerInjector = createInternalInjector(providerCache, function() {
throw Error("Unknown provider: " + path.join(' <- '));
}),这是代码:
var myApp = angular.module('myApp', [], function ($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
myApp.directive('buttonsRadio', function() {
[...]
});
myApp.controller('MainController', function MainController ($scope) {
[...]
})有什么想法吗?
编辑:添加错误消息:
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发布于 2013-12-09 09:12:54
在运行uglify或任何其他ofuscator/压缩算法之前,您应该运行grunt任务ng-annotate,它将依赖项作为可注入数组添加到字符串中,这使得代码更加清晰,因为可以作为构建步骤自动添加可注入注释,而不必手动对其进行编码。
myApp.controller('MainController', function MainController ($scope) {
[...]
})变成:
myApp.controller('MainController', ['$scope', function MainController ($scope) {
[...]
}])看看:https://github.com/olov/ng-annotate
更新: 吴民 AngularJS预处理器废弃的->使用ng注解
发布于 2013-04-26 18:00:41
我假设您使用的是某种javascript obufuscator (Clousure、SquishIt、UglifyJS等)。
在这种情况下,您需要以这样的方式指定依赖关系:
var myApp = angular.module('myApp', [], ['$interpolateProvider',function ($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
}]);
myApp.directive('buttonsRadio', function() {
[...]
});
myApp.controller('MainController',['$scope', function MainController ($scope) {
[...]
}])注要为依赖项注入指定依赖项--而不是传递函数,您需要指定带有字符串列表的数组,其中包含要注入到参数中的对象名称和函数本身。
https://stackoverflow.com/questions/16242406
复制相似问题