繁体   English   中英

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

[英]Angular JS - Uncaught Error: [$injector:modulerr].

您能帮我摆脱错误“未捕获的错误:[$ injector:modulerr]”。 我厌倦了调试Angularjs应用程序,很难捕获错误,我已经习惯了Java,并且由于我有调试器,因此可以轻松捕获错误。 但是如果是AngularJS,那是不可能的。 非常感谢!

的index.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>

customers.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>

app.js

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

customersController.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: '/'});
    });
})();

工作朋克

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM