Error: [$injector:unpr] Unknown provider: $routeProvider

前端 未结 2 400
一向
一向 2020-12-24 00:29

I am trying to get an AngularJS 1.2 RC2 app up and running. Currently, I\'ve been using the Angular Seed project to try and get my app up and running. Unfortunately, the Ang

相关标签:
2条回答
  • 2020-12-24 00:55

    It looks like you forgot to include the ngRoute module in your dependency for myApp.

    In Angular 1.2, they've made ngRoute optional (so you can use third-party route providers, etc.) and you have to explicitly depend on it in modules, along with including the separate file.

    'use strict';
    
    angular.module('myApp', ['ngRoute']).
        config(['$routeProvider', function($routeProvider) {
    $routeProvider.otherwise({redirectTo: '/home'});
    }]);
    
    0 讨论(0)
  • 2020-12-24 01:07

    In angular 1.4 +, in addition to adding the dependency

    angular.module('myApp', ['ngRoute'])
    

    ,we also need to reference the separate angular-route.js file

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

    see https://docs.angularjs.org/api/ngRoute

    0 讨论(0)
提交回复
热议问题