2013-08-28 154 views
213

從AngularJS升級後我收到此錯誤1.0.71.2.0rc1

回答

402

ngRoute模塊不再是核心angular.js文件的一部分。如果您繼續使用$ routeProvider那麼你現在需要包括angular-route.js在你的HTML:

<script src="angular.js"> 
<script src="angular-route.js"> 

API Reference

您還必須添加ngRoute爲您的應用程序的依賴:

var app = angular.module('MyApp', ['ngRoute', ...]); 

如果您正計劃使用angular-ui-router或類似方法,則只需從模塊.config()中刪除$routeProvider依賴項,並將其替換爲相關的pro選擇的視頻(例如, $stateProvider)。這樣,你會使用ui.router依賴性:

var app = angular.module('MyApp', ['ui.router', ...]); 
+2

好像'UI-router'項目可能是一個更靈活的選擇,如果你從頭(https://github.com/angular-開始ui/ui-router) – gatoatigrado

+0

It works,thanks :) –

+2

@gatoatigrado - 我剛從'angular-ui-router' ** v0.0.1 **升級我的應用程序時'ui.state'的語法已經過時了。到** v0.2.0 **,這意味着它現在使用'ui.router'名稱。我對造成的任何困惑表示歉意。 –

40

添加到斯科蒂的回答是:

選項1: 無論是包括這在你的JS文件:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script> 

選項2: 或只使用將「angular-route.min.js」下載到本地的URL。

然後(無論你選擇什麼選項)添加這個'ngRoute'作爲依賴。

解釋說: var app = angular.module('myapp', ['ngRoute']);

乾杯!

+5

對不起,但我不得不承認,這似乎非常類似於已經提供的答案?? –

+2

...在其他地方,我發現人們無法找到鏈接/ URL來下載或引用'angular-route.min.js'。 這就是我在答案中給出的和是的,我同意你談論的'ngRoute'依賴關係,所以我在我的答案中也添加了這一點。 – mayankcpdixit

+0

我比js圖書館地獄有點累。當然必須有比通過模塊找出合適的堆棧模塊更好的方法。 – 2014-05-13 20:08:21

3

在我的情況下,這是因爲該文件被縮小了錯誤的範圍。使用數組!

app.controller('StoreController', ['$http', function($http) { 
    ... 
}]); 

咖啡語法:

app.controller 'StoreController', Array '$http', ($http) -> 
    ... 
相關問題