未捕获的错误:即使在加载ng-route后也是Angular

时间:2016-07-30 17:33:22

标签: javascript angularjs

我收到了这个可怕的错误:

www.

不确定我做错了什么:app.js:

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module usersApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:
Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

的index.html:

(function () {

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

    app.config(['$routeProvider', function ($routeProvider) {

      var viewBase = '/';

        $routeProvider
            .when('/users', {
                controller: 'MainController',
                templateUrl: viewBase + 'users/users.html',
                controllerAs: 'vm'
            })
            .when('/add', {
                controller: 'OrdersController',
                templateUrl: viewBase + 'add/orders.html'
            })
            .otherwise({ redirectTo: '/users' });

    }]);


}());

感谢您提供的任何帮助!

2 个答案:

答案 0 :(得分:2)

您忘了加入angular-route。 此外,无需加载2个不同版本的角度。将您的主要HTML更改为:

<html>
  <head>
    <title>My Angular App!</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-route.min.js"></script>

    <script src="app.js"></script>
  </head>
  <body ng-app="usersApp" ng-controller="MainCtrl">
  <h1>uSers</h1>
    <div ng-repeat="user in users" ng-click="getUsers()" style="background: black; padding: 5px; min-width: 25px; color: white;">
    {{user}}
    </div>
  </body>
</html>

答案 1 :(得分:1)

您缺少在index.html中包含angular.route.js