简体   繁体   English

AngularJS:$ injector:使用ngAnimate时出现unpr错误

[英]AngularJS: $injector:unpr error when using ngAnimate

I am trying to add ngAnimate to my angular app dependencies. 我正在尝试将ngAnimate添加到我的角度应用程序依赖项中。 Here is my angular app file: 这是我的角度应用程序文件:

var carApp = angular.module("carApp", ["ngAnimate"]);

Here is my TableBodyCtrl controller: 这是我的TableBodyCtrl控制器:

carApp.controller("TableBodyCtrl", function($scope, $http){
    $scope.loading = false;
    ...
});

Here is my TablePanelCtrl : 这是我的TablePanelCtrl

carApp.controller("TablePanelCtrl", function(){
    this.tab = 1;
    ...
});

My controller are in different files in the controller folder. 我的控制器位于controller文件夹中的不同文件中。

Here is the script loads of angular libraries: 这是角度库的脚本加载:

<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/angular-animate.min.js"></script> 

Here is the script load of my angular app file: 这是我的角度应用程序文件的脚本加载:

<script type="text/javascript" src="js/carApp.js"></script>

Here is the script loads of my controllers: 这是我的控制器的脚本加载:

<script type="text/javascript" src="js/controllers/TablePanelCtrl.js"></script>
<script type="text/javascript" src="js/controllers/TableBodyCtrl.js"></script>

When I run my web-app I get this error: 当我运行我的网络应用程序时,我收到此错误:

Unknown provider: $$qProvider <- $$q <- $animate <- $compile

https://docs.angularjs.org/error/$injector/unpr?p0=$$qProvider%20%3C-%20$$q%20%3C-%20$animate%20%3C-%20$compile

This error only started to show up after I add "ngAnimate" to my angular app dependencies. 在我将"ngAnimate"添加到我的角度应用程序依赖项后,此错误才开始显示。

How can I fix that? 我该如何解决这个问题?

I had the same error and just figured out why it was happening. 我有同样的错误,只是弄清楚它为什么会发生。

The root cause was I was depending on "angular-animate": "~1.3.0", so bower was using Angular v1.3 even though the rest of the project was depending on Angular 1.2. 根本原因是我依赖于“角度 - 动画”:“~1.3.0”,所以凉亭使用Angular v1.3,即使项目的其余部分依赖于Angular 1.2。

Just use 只是用

"angular-animate": "~1.2.0"

instead of 代替

"angular-animate": "~1.3.0"

in your bower.json file. 在你的bower.json文件中。 After a bower install everything should work! bower install一切都应该工作!

Same answer here: https://stackoverflow.com/a/26596023/2171509 同样的答案: https//stackoverflow.com/a/26596023/2171509

我有同样的问题,解决了

bower update.

I've set up the exact same setup as you provided in this plnkr , 我已经设置了与此plnkr中提供的完全相同的设置,

There are no errors there. 那里没有错误。 What you're doing is correct. 你正在做的是正确的。

The order of files and the module creation with 'ngAnimate' as dependency 以“ngAnimate”作为依赖关系的文件顺序和模块创建

var carApp = angular.module("carApp", ["ngAnimate"]);

is the right way to do it. 是正确的方法。

Altough, one point to keep in mind: 尽管如此,要记住一点:

from Angularjs docs 来自Angularjs docs

There are two types of angular script URLs you can point to, one for development and one for production: 您可以指向两种类型的角度脚本URL,一种用于开发,另一种用于生产:

angular.js — This is the human-readable, non-minified version, suitable for web development. angular.js - 这是人类可读的非缩小版本,适用于Web开发。 angular.min.js — This is the minified version, which we strongly suggest you use in production. angular.min.js - 这是缩小版本,我们强烈建议您在生产中使用。

same goes for angular-animate.js. angular-animate.js也是如此。

This will help you in development while it'll show you better error reports. 这将有助于您进行开发,同时它会向您显示更好的错误报告。

Another point is even when using minified angularjs version, you get a link to the 'long descriptive' error msg, and by looking the link your provided with your error msg, I saw this: 另一点是,即使使用缩小的angularjs版本,您也会获得“长描述性”错误消息的链接 ,通过查看您提供的错误消息的链接 ,我看到了:

An unknown provider error can also be caused by accidentally redefining a module using the angular.module API, as shown in the following example. 使用angular.module API意外重新定义模块也可能导致未知的提供程序错误,如以下示例所示。

 angular.module('myModule', []) .service('myCoolService', function () { /* ... */ }); angular.module('myModule', []) // myModule has already been created! This is not what you want! .directive('myDirective', ['myCoolService', function (myCoolService) { // This directive definition throws unknown provider, because myCoolService // has been destroyed. }]); 

To fix this problem, make sure you only define each module with the angular.module(name, [requires]) syntax once across your entire project. 要解决此问题,请确保在整个项目中仅使用angular.module(name,[requires])语法定义每个模块一次。 Retrieve it for subsequent use with angular.module(name). 检索它以便随后使用angular.module(name)。 The fixed example is shown below. 固定示例如下所示。

 angular.module('myModule', []) .service('myCoolService', function () { /* ... */ }); angular.module('myModule') .directive('myDirective', ['myCoolService', function (myCoolService) { // This directive definition does not throw unknown provider. }]); 

I had the same issue, the reason seems to be conflict between versions of these libraries. 我有同样的问题,原因似乎是这些库的版本之间的冲突。

I didn't see this error after I updated to AngularJS v1.3.14 from v 1.2 . v 1.2更新到AngularJS v1.3.14后,我没有看到这个错误。 Try different versions & check their compatibility. 尝试不同版本并检查其兼容性。

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

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