216

I received this error upon upgrading from AngularJS 1.0.7 to 1.2.0rc1.

Scotty.NET
  • 12,533
  • 4
  • 42
  • 51

3 Answers3

404

The ngRoute module is no longer part of the core angular.js file. If you are continuing to use $routeProvider then you will now need to include angular-route.js in your HTML:

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

API Reference

You also have to add ngRoute as a dependency for your application:

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

If instead you are planning on using angular-ui-router or the like then just remove the $routeProvider dependency from your module .config() and substitute it with the relevant provider of choice (e.g. $stateProvider). You would then use the ui.router dependency:

var app = angular.module('MyApp', ['ui.router', ...]);
Scotty.NET
  • 12,533
  • 4
  • 42
  • 51
  • 2
    Seems like the `ui-router` project may be a more flexible alternative, if you're starting from scratch (https://github.com/angular-ui/ui-router) – gatoatigrado Sep 04 '13 at 23:49
  • 2
    @gatoatigrado - I just realised how old the `ui.state` syntax was when I upgraded my app from `angular-ui-router` **v0.0.1** to **v0.2.0**, which means it now uses the `ui.router` name. My apologies for any confusion caused. – Scotty.NET Nov 13 '13 at 17:12
  • 3
    Where is the CDN address for `angular-route.js`? – Ala Dec 01 '13 at 07:58
  • @SaharSany - The [documentation for `angular-route`](http://docs.angularjs.org/api/ngRoute) gives the CDN address as well as other options. As for [`ui-router`](https://github.com/angular-ui/ui-router) there is currently no CDN that I know of. – Scotty.NET Dec 01 '13 at 11:24
  • 3
    `ui-router` doesn't seem to be on its own CDN, though it is on cdnjs: http://cdnjs.com/libraries/angular-ui-router – Nick McCurdy Aug 06 '14 at 10:03
  • Calling a page reload with ui-router seen at http://stackoverflow.com/questions/21714655/angular-js-angular-ui-router-reloading-current-state-refresh-data – Stephane Oct 01 '14 at 13:16
41

adding to scotty's answer:

Option 1: Either include this in your JS file:

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

Option 2: or just use the URL to download 'angular-route.min.js' to your local.

and then (whatever option you choose) add this 'ngRoute' as dependency.

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

Cheers!!!

Mo.
  • 26,306
  • 36
  • 159
  • 225
mayankcpdixit
  • 2,456
  • 22
  • 23
  • 5
    Sorry but I have to admit that this seems very similar to the answer already provided?? – Scotty.NET Oct 27 '13 at 22:14
  • 2
    ...at other places I found that people are not able to find the link/ URL to download or refer the 'angular-route.min.js'. That's what I gave in Answer and Yes I agree to 'ngRoute' Dependency you talked about, so I added that too in My answer. – mayankcpdixit Oct 28 '13 at 04:46
  • I am more than a bit tired of js library hell. Surely there has to be a better way than figuring out the proper stack module by module. –  May 13 '14 at 20:08
  • This is how it's done @SamanthaAtkins, If you know what's needed you inject the dependency and include the JS file if you don't have code for that Dependency. Although I'd appreciate a better way if someone suggests. – mayankcpdixit Jun 13 '14 at 14:30
3

In my case it was because the file was minified with wrong scope. Use Array!

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

Coffee syntax:

app.controller 'StoreController', Array '$http', ($http) ->
  ...
Lucia
  • 13,033
  • 6
  • 44
  • 50