Angular JS - 未捕获的错误: [$injector:modulerr].



你能帮我摆脱错误"未捕获的错误:[$injector:modulerr]"吗?我厌倦了调试 Angularjs 应用程序,很难捕获错误,我习惯了 Java,并且有一个简单的捕获错误,因为我有一个调试器。但是在AngularJS的情况下,这是不可能的。多谢!

索引.html

<!doctype html>
<html ng-app="customersApp">
  <head>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script>
    <script src="app/controllers/app.js"></script>
    <script src="app/controllers/customersController.js"></script>
  </head>
  <body>
    <div class="container">
      <div ng-view></div>
    </div>
  </body>
</html>

客户.html

<div class="row">
     <h2>Customers</h2>
     Filter: <input type="text" ng-model="customerFilter.name">
     <br><br>
     <table class="table table-bordered">
       <tr class="active">
         <th ng-click="doSort('name')">Name</th>
         <th ng-click="doSort('city')">City</th>
         <th ng-click="doSort('orderTotal')">Order Total</th>
         <th ng-click="doSort('joined')">Joined</th>
       </tr>
       <tr ng-repeat="cust in customers | filter:customerFilter | orderBy:sortBy:reverse">
         <td>{{cust.name}}</td>
         <td>{{cust.city}}</td>
         <td>{{cust.orderTotal | currency}}</td>
         <td>{{cust.joined | date: 'yyyy-MM-dd'}}</td>
       </tr>
     </table>
</div>

应用.js

(function(){
    var app = angular.module('customersApp', ['ngRoute']);
    app.config(function($routeProvider) {
        $routeProvider
            .when('/', {
                controller: 'CustomersController',
                templateUrl: 'app/views/customers.html'
            })
            .otherwice({redirectTo: '/'});
    });
})();

客户控制器.js

(function(){
  var CustomersController = function($scope) {
    $scope.sortBy = 'name';
    $scope.reverse = false;
    $scope.customers = [
      {joined: '2012-12-02', name: 'John', city: 'Luhansh', orderTotal: 9.99},
      {joined: '2012-09-14', name: 'Sergey', city: 'Kyiv', orderTotal: 5.799},
      {joined: '2015-11-03', name: 'Denis', city: 'Warsaw', orderTotal: 1.35}
    ];
    $scope.doSort = function(propName) {
      $scope.sortBy = propName;
      $scope.reverse = !$scope.reverse;
    }
  };
  CustomersController.$inject = ['$scope'];
  angular.module('customersApp')
    .controller('CustomersController', CustomersController);
})();

你的问题是你的app.js有错别字

.otherwice({redirectTo: '/'});应该.otherwise({redirectTo: '/'});

(function(){
    var app = angular.module('customersApp', ['ngRoute']);
    app.config(function($routeProvider) {
        $routeProvider
            .when('/', {
                controller: 'CustomersController',
                templateUrl: 'app/views/customers.html'
            })
            .otherwise({redirectTo: '/'});
    });
})();

工作普伦克

最新更新