2014-03-26 73 views
0

即使在將ngRoute文件和ngRoute包含在dependencyInjection中之後,仍然出現以下錯誤。

未捕獲的錯誤:

[$injector:modulerr] http://errors.angularjs.org/1.2.7/$injector/modulerr?p0=demoModule&p1=Error….org%2F1.2.7%2F%24injector%2Funpr%3Fp0%3D%2524routeprovider%0A%20%20%20%20...<omitted>...2) 

來源:

<head> 
    <title>Intro to Angular js </title> 
</head> 

<body> 
    <div> 
     <div data-ng-view=""></div> 
    </div> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script> 
    <script> 
     var demoApp = angular.module ('demoModule' , ["ngRoute"]); 

     demoApp.controller ('SimpleController', function ($scope) { 
      $scope.persons = [ {name: "xxx", city: "St.Louis"}, {name: "yyyy", city: "NY"}, {name: "zzzz", city: "Seattle"} ]; 
      $scope.addCustomer = function () { 
        $scope.persons.push ({name: $scope.customerName, city: $scope.customerCity}) 
      } 
     }); 

     demoApp.config (function ($routeprovider) { 
      $routeprovider 
       .when ('/', 
         { 
          controller: 'SimpleController', 
          templateUrl: 'View1.html' 
         }) 
       .when ('/view2', 
         { 
          controller: 'SimpleController', 
          templateUrl: 'View2.html'        
         }) 
       .otherwise ({ redirectTo:'/'}); 
     }); 

    </script> 
</body> 
+1

它應該是'$ routeProvider'(camelCase)。 –

回答

1

安東尼楚說,你已命名的錯誤,需要從$routeprovider更改爲$routeProvider

例子:

demoApp.config (function ($routeProvider) { 
    $routeProvider 
     .when ('/', 
       { 
        controller: 'SimpleController', 
        templateUrl: 'View1.html' 
       }) 
     .when ('/view2', 
       { 
        controller: 'SimpleController', 
        templateUrl: 'View2.html'        
       }) 
     .otherwise ({ redirectTo:'/'}); 
}); 

活生生的例子:http://jsfiddle.net/choroshin/6dsr6/

1

我調查,發現了一些東西,可能導致此問題。它們是:

  1. 確保'$ routeprovider'應該更改爲正確的名稱'$ routeProvider'。
  2. 確保將'demoModule'模塊添加到您的應用程序中。

讓一切更清楚,我已經創建了一個樣本,與您的應用程序非常相似。詳情請參閱here

HTML

<body ng-app="demoModule"> 
    <div> 
     <div data-ng-view=""></div> 
    </div> 
</body> 

JS

​​

希望這將幫助你!並請讓我知道是否有問題

相關問題