angularjs - 未知的提供者 : ngTagsInputProvider <- ngTagsInput

标签 angularjs angularjs-service ng-tags-input

我将这样的 2.1.1 版本的 ngtagsinput 注入(inject)到我的 Controller 中:

app.controller('homeCtrl', ['$scope','$http','ngTagsInput', function($scope,$http){
}])

*注意:已测试!将 ngTagsInput 添加到 function() 中不会有任何区别...

我在 angularjs 库之后加载了 ngtagsinput 库。

我想知道我还能测试什么来解决以下错误:

Error: [$injector:unpr] Unknown provider: ngTagsInputProvider <- ngTagsInput
http://errors.angularjs.org/1.2.9/$injector/unpr?p0=ngTagsInputProvider%20%3C-%20ngTagsInput

不要误会我的意思,我知道基本上没有检测到这个提供程序。

但是找到了我的库(没有报告 404),我看到它的库中使用了 ngTagsInput....

所以,它真的困扰着我,同样的解决方案不再适用于这个库!这个库有什么特别之处,为什么在我达到修复它的所有标准时会出现这个错误?

最佳答案

看起来您已尝试将 ngTagsInput 注入(inject)到您的 Controller 中,而您应该将其作为依赖项注入(inject)到您的模块中。例如:

angular.module('myApp', ['ngTagsInput'])

注意模块,而不是 Controller

您可以按照创建者的示例查看:https://github.com/mbenford/ngTagsInput#example


发生这种情况是因为 Angular 中使用了多种类型的注入(inject)。当您声明一个模块时,您需要指定在您的模块中可以使用哪些其他模块。

见:https://docs.angularjs.org/guide/module

当你注入(inject)一个 Controller 时,你基本上是在说你想在其中使用一个特定的对象。该对象必须是模块的一部分才能有效。对于第三方库,这通常意味着将其添加为模块依赖项(如上所述),然后将属于该库的任何对象注入(inject)到您的 Controller 和服务中。

关于angularjs - 未知的提供者 : ngTagsInputProvider <- ngTagsInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25833260/

相关文章:

javascript - Angular js : splitting up a large controller into multiple files

javascript - 如何从 Controller 内访问服务返回的对象

angularjs - ng-tags-input,如何禁用用户输入?

javascript - 否定 Javascript 正则表达式模式

javascript - 设置 addFromAutocompleteOnly 时,剩余文本留在输入字段中

javascript - 输入空格时如何触发 ng-change?

javascript - Angular 函数在模型更新之前触发 : Zipcode checker

javascript - ng-if 消除了 Material Design lite 涟漪效应

AngularJS:混淆 $scope 中的对象引用

javascript - Angular : Service variable changes not applying