Failed to instantiate module [$injector:unpr] Unknown provider: $routeProvider

后端 未结 3 530
囚心锁ツ
囚心锁ツ 2020-11-28 20:26

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

相关标签:
3条回答
  • 2020-11-28 21:02

    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', ...]);
    
    0 讨论(0)
  • 2020-11-28 21:08

    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!!!

    0 讨论(0)
  • 2020-11-28 21:10

    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) ->
      ...
    
    0 讨论(0)
提交回复
热议问题