首页 > 解决方案 > 将 VividCortex angular-recaptcha 依赖项添加到 AngularJS 模块时出错

问题描述

我正在尝试将 Google reCaptcha v2 添加到我的 AngularJS 应用程序中。我正在尝试使用 VividCortex 的 angular-recaptcha,但我无法将依赖项添加到我的应用程序模块中。

我的模块的原始代码是这样的:

angular.module("myApp")
.config(['$httpProvider','jwtInterceptorProvider', function Config($httpProvider, jwtInterceptorProvider) {
  //do stuff
}])

.config([ '$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
    //do other stuff
}])

.factory('httpRequestInterceptor', ['API_KEY', function(API_KEY) {
    //do more stuff
}]);

我一直在尝试添加依赖项,就像它在文档中一样:

angular.module("myApp", ['vcRecaptcha'])

但它给了我这个错误:

未捕获的错误:[$injector:modulerr] 无法实例化模块 myApp 由于:错误:[$injector:unpr] 未知的提供者:jwtInterceptorProvider

如果我不尝试添加依赖项,我不会收到此错误。

提前致谢!

标签: angularjsrecaptcha

解决方案


问题解决了。我对 AngularJS 缺乏了解,这让我认为这是创建模块的地方,但它只是被检索,所以当我添加依赖项时,我再次创建它而没有 jwtInterceptor 依赖项,因此出现错误消息。我找到了创建模块的位置,添加了依赖项,现在它可以工作了。


推荐阅读