2014-10-02 48 views
13

我正在嘗試將ngAnimate添加到我的角度應用程序依賴項中。這是我的角度app文件:

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

這裏是我的TableBodyCtrl控制器:

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

這裏是我的TablePanelCtrl

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

我的控制器都在controller文件夾不同的文件。

這裏是角庫的腳本加載:

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

這裏是我的角度應用程序文件的腳本負荷:

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

這裏是我的控制器的腳本加載:

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

當我運行我的網絡應用程序時,出現此錯誤:

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 

此錯誤僅在我將角色應用依賴關係添加"ngAnimate"後纔會顯示。

我該如何解決這個問題?

+0

你使用哪種角度的角度?嘗試添加它的調試版本以獲取更多的錯誤信息 – 2014-10-02 10:21:07

+0

AngularJS v1.2.18 – 2014-10-02 10:22:38

+0

Angular-Animate-AngularJS v1.3.0-build.3317 + sha.a1648a7 – 2014-10-02 10:28:43

回答

2

我已經設置了完全相同的設置爲你在這個plnkr

提供沒有錯誤存在。你在做什麼是正確的。

文件的順序和模塊創建與「ngAnimate」作爲依賴

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

是做正確的方式。

Altough,有一點要記住:

從Angularjs docs

There are two types of angular script URLs you can point to, one for development and one for production:

angular.js — This is the human-readable, non-minified version, suitable for web development. angular.min.js — This is the minified version, which we strongly suggest you use in production.

同樣適用於角animate.js。

這會幫助您進行開發,同時它會向您顯示更好的錯誤報告。

的另一點是,即使使用精縮angularjs版本時,你會得到一個鏈接到「長描述」錯誤味精,並通過查找link您提供您的錯誤味精,我看到了這一點:

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('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. Retrieve it for subsequent use with 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. 
}]); 
+0

plunker鏈接不再工作 – 2017-11-16 21:30:14

33

我有同樣的錯誤,只是想出了它爲什麼發生。

根本原因是我依賴於「angular-animate」:「〜1.3.0」,所以bower使用了Angular v1.3,即使項目的其餘部分依賴於Angular 1.2。

在bower.json文件只需使用

"angular-animate": "~1.2.0" 

,而不是

"angular-animate": "~1.3.0" 

。經過一個bower install一切應該工作!

同樣的答案在這裏:https://stackoverflow.com/a/26596023/2171509

+0

不錯的一個:)值得一提bower自己安裝的angular-animate允許後綴@ [ng-version],這是推薦的。如果我使用了它,我會避免這個問題。 – Astravagrant 2014-10-29 14:38:13

+0

完美。這是我的問題!我使用的是AngularJS v1.2.9,http://..../1.3.3/angular-animate.min.js,所以我改爲http://..../1.2.9/angular-animate.min .js和這個變化就像一個魅力 – 2015-04-21 11:48:30

+0

謝謝!在此日期(2015年9月),開箱即用角度多功能AngularJs主題就是這種情況。 – meesern 2015-09-02 11:06:24

5

我同樣的問題,通過

bower update. 
+1

解決了我的問題。 – 2014-12-09 09:42:08

0

解決我有同樣的問題,原因似乎是這些庫的版本之間的衝突。

我從v 1.2更新至AngularJS v1.3.14後沒有看到此錯誤。嘗試不同的版本&檢查它們的兼容性。

相關問題