2016-04-07 76 views
1

我用角1.5.3,但是當我注入「ngRoute」我得到的錯誤是這樣的:錯誤時注入ngRoute

angular.js:38Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.3/ $injector/modulerr?p0=scotchApp&p1=Error%…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.3%2Fangular.min.js%3A20%3A463)(anonymous function) @ angular.js:38(anonymous function) @ angular.js:4547q @ angular.js:321g @ angular.js:4508eb @ angular.js:4430c @ angular.js:1710yc @ angular.js:1731de @ angular.js:1616(anonymous function) @ angular.js:30709b @ angular.js:3127Pf @ angular.js:3417Of.d @ angular.js:3405

這裏是代碼

var scotchApp = angular.module('scotchApp', ['ngRoute']); 
    scotchApp.config(function($routeProvider) { 
     $routeProvider 
      .when('/', { 
       templateUrl : 'home.html', 
       controller : 'mainController' 
      }) 
      .when('/about', { 
       templateUrl : 'about.html', 
       controller : 'aboutController' 
      }) 
      .when('/contact', { 
       templateUrl : 'contact.html', 
       controller : 'contactController' 
      }); 
    }); 
    scotchApp.controller('mainController', function($scope) { 
     // create a message to display in our view 
     $scope.message = 'Everyone come and see how good I look!'; 
    }); 
    scotchApp.controller('aboutController', function($scope) { 
     $scope.message = 'Look! I am an about page.'; 
    }); 
    scotchApp.controller('contactController', function($scope) { 
     $scope.message = 'Contact us! JK. This is just a demo.'; 
    }); 
</script> 
</head> 
<body ng-controller="mainController"> 
    <div id="main"> 
     <div ng-view></div> 
    </div> 
</body> 
</html> 

請幫我解決這個問題

謝謝

+1

您是否已將'angular-route.js'添加到index.html文件中,並且順序正確? – M22an

+0

也使用angular.js的unminified版本有助於調試 – jithin

回答

0

模塊ngRoute不在主要的角度腳本。它在angular-route.js。確保你在你的頁面中包含這個腳本。

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

按照docs爲1.5.3:

You can download this file from the following places:

where X.Y.Z is the AngularJS version you are running.

有關詳細信息,請參閱docsngRoute

+0

謝謝,我要試一下,看看它是否工作 – user1186850

+0

我已經添加了它,但我仍然有這個錯誤 – user1186850