错误未捕获错误:[$ injector:modulerr] angularjs

时间:2014-02-14 07:22:37

标签: javascript angularjs angularjs-routing

我正在使用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)

1 个答案:

答案 0 :(得分:8)

  1. 请务必在angular.js

    之后加入angular-route.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。通过使用服务作为依赖项,它不能注入错误的参数名称。