AngularJS路由示例给出未捕获错误:[$ injector:modulerr]

时间:2015-05-09 13:29:30

标签: javascript angularjs

我是Angular JS的新手。我使用的是Angular JS 1.3.15版 这是我为路线写的代码。但是我在谷歌浏览器中遇到以下异常 -

   Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=app&p1=Error%3A%20…wala%2FDesktop%2FPersonal%2520Work%2FAngularJS%2Fangular.min.js%3A38%3A135

代码是 -

<html ng-app="app">
<head>
<title>Sample Angular JS application - routes example</title>
<script src="angular.min.js" type="text/javascript">
</script>

<script>
 var app = angular.module('app',[]);

  app.config(function ($routeProvider) {
       $routeProvider
       .when('/', {
             controller : 'SimpleController',
             templateUrl : 'routes/view1.html'
          })
       .when('/view2', {
             controller : 'SimpleController',
             templateUrl : 'routes/view2.html'
          })
        .otherwise({
             redirectTo: '/'
          });
    });

     app.controller('SimpleController',['$scope',
         function ($scope) {
              $scope.customers = [
                 {name: 'Akshay Kumar' , city: 'Chandigarh'},
                 {name: 'Madhuri Dixit' , city: 'Mumbai'},
                 {name: 'Shah Rukh Khan' , city: 'Delhi'},
                 {name: 'Anil Kumble' , city: 'Bangalore'},
                 {name: 'Rishi Kanitkar' , city: 'Pune'},
                 {name: 'Dhanraj Pillai' , city: 'Pune'}
               ];

               $scope.addCustomer = function() {
               $scope.customers.push(
                {
                    name: $scope.newCustomer.name , 
                    city: $scope.newCustomer.city
                });
           }
        }]);
       </script>
     </head>

     <body> 
        <div>
        <!-- Placeholder for the views -->
        <div ng-view=""></div>
       </div>
     </body>
    </html>

如何解决此错误?

1 个答案:

答案 0 :(得分:1)

你错过了几件事

  1. angular-route.min.js
  2. 的脚本参考
  3. 您的应用宣言中缺少ngRoute
  4. <强>代码

    var app = angular.module('app',['ngRoute']);