2014-02-14 104 views
1

我使用angularjs路由,但得到以下錯誤...

<title>Angular js</title> 

</head> 
<body><div data-ng-controller="SimpleController"> 
    <div data-ng-view=""></div> 
    NAme:<input type="text" data-ng-model="name" />{{name}} 
    <br /> 
    <ul> 
     <li data-ng-repeat="cust in customers|filter:name|orderBy:'city'">{{cust.name|uppercase}}-{{cust.city|lowercase}}</li> 
    </ul> 
     <script> 
       var demoapp = angular.module('demoapp', ['ngRoute']); 
       demoapp.config(function($routeprovider){ 
        $routeprovider 
        .when('/',{ 
        controller:'SimpleController', 
        templateUrl:'view1.html' 
       }) 
        .when('/partial2',{ 
       controller:'SimpleController', 
       templateUrl:'view2.html' 
       }) 
        .otherwise({redirectTo:'/'}); 
       }); 
      demoapp.controller('SimpleController', 
      function ($scope) { 
       $scope.customers = [{ name: 'aman', city: 'boom' }, 
            { name: 'ajay', city: 'reem dee' }, 
            { name: 'hood', city: 'meen' }]; 
      }); 
     </script> 
    </div> 
</body> 
</html> 

錯誤控制檯上

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.12/$injector/modulerr?p0=demoapp&p1=Error%3…0Yb%20(http%3A%2F%2Flocalhost%3A4257%2Fscripts%2Fangular.min.js%3A32%3A232) 
+2

我認爲你必須寫$ routeProvider –

+0

你有沒有加入?

回答

8
  1. 確保在包含您的angular-route.js後angular.js

    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular-route.js"></script> 
    
  2. $routeprovider替換爲$routeProvider。通過使用服務作爲依賴項,它不能注入錯誤的參數名稱。

+0

解決了。 thnx v多 –

相關問題