2

今日、 AngularJSの学習を開始しましたが、 「ルーティング」の部分で行き詰まっています。コントローラーとビュー (以下を参照) を作成しましたが、ローカル サーバーで実行しようとすると、次のエラーが発生します。

Uncaught Error: [$injector:modulerr] Failed to instantiate module AMail due to: 
Error: [$injector:unpr] Unknown provider: $routeProvider

ngRouteサービスが Angular に組み込まれている場合、エラーが不明であることを示唆するのはなぜですか?

controller.js

var aMailServices = angular.module('AMail', []);
// Set up our mappings between URLs, templates, and controllers
    function emailRouteConfig($routeProvider) {
        $routeProvider.
        when('/', {
           controller: ListController,
           templateUrl: 'list.html'
        }).
        when('/view/:id', {
           controller: DetailController,
           templateUrl: 'detail.html'
        }).
        otherwise({
           redirectTo: '/'
       });
   }

// Set up our route so the AMail service can find it
aMailServices.config(emailRouteConfig);

messages = [{
       id: 0, 
           sender: 'jean@somecompany.com', 
           subject: 'Hi there, old friend',
       date: 'Dec 7, 2013 12:32:00', 
           recipients: ['greg@somecompany.com'],
           message: 'Hey'
       }];

// Publish our messages for the list template
function ListController($scope) {
    $scope.messages = messages;
}

// Get the message id from the route (parsed from the URL) and use it to
// find the right message object.
function DetailController($scope, $routeParams) {
    $scope.message = messages[$routeParams.id];
}

index.html

<html ng-app="AMail">
  <head>
  </head>
  <body>
    <h1>A-Mail</h1>
    <div ng-view></div>
    <script src="angular.js"></script>
    <script src="controller.js"></script>
  </body>
</html>
4

1 に答える 1

5

ngRoute への依存関係を宣言する必要があります。

var aMailServices = angular.module('AMail', ['ngRoute']);
于 2014-04-26T13:28:42.460 に答える