0

私はangularJSを使用しており、ルーティングをアプリケーションに追加したいと考えています。アプリでルーティングが機能しないのはなぜですか?

var countryApp = angular.module('countryApp', ['ngRoute', 'countriesDataModule']); 

countryApp.config(['$routeProvider', function ($routeProvider) { 
    $routeProvider.when('data/', { 
     templateUrl : 'partials/countries.html', 
     controller : 'CountriesListCtrl' 
    }).when('data/:countryUrl', { 
     templateUrl : 'partials/country-details.html', 
     controller : 'CountryDetailsCtrl' 
    }).otherwise({ 
     redirectTo : '/countries' 
    }); 
}]); 

およびファイルcontrollers.js:

var countriesDataModule = angular.module('countriesDataModule', []); 

countriesDataModule.controller('CountriesListCtrl', ['$scope', '$http', function ($scope, $http) { 
    $http.get('data/countries.json').success(function (data) { 
     $scope.countries = data; 
     $scope.selectedProp = 'countryId'; 
    }); 
}]); 

countriesDataModule.controller('CountryDetailsCtrl', ['scope', '$routeParams', function ($scope, $routeParams) { 
    $scope.countyUrl = $routeParams.countryUrl; 
}]); 

index.htmlファイル:

<!DOCTYPE html> 
<html lang="en" ng-app="countriesModule"> 
<head> 
    <meta charset="UTF-8"> 
    <link rel="stylesheet" type="text/css" href="css/common.css"> 
    <script src="bower_components/jquery-2.2.3.min/jquery-2.2.3.min.js"></script> 
    <script src="bower_components/angular/angular.js"></script> 
    <script src="bower_components/angular-route/angular-route.js"></script> 
    <script src="js/app.js"></script> 
    <script src="js/controllers.js"></script> 
    <title>Document</title> 
</head> 
<body> 
<div class="container"> 
    <header> 
     <h1>Сountry for travel</h1> 
    </header> 
    <main> 
     <div ng-view></div> 
    </main> 
</div> 
</body> 
</html> 

Uncaught Error: [$injector:modulerr] Failed to instantiate module countriesModule due to: 
Error: [$injector:nomod] Module 'countriesModule' 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. 

これは私のファイルapp.jsです:しかし、私はエラーが持っています

私のプロジェクトの構成:

enter image description here

私は他のページを訪問し、そこにいくつかのヒントを見てきました:コードあなたの中にcountriesModuleと呼ばれるものへの言及はありません

AngularJS 1.2 $injector:modulerr

Angular JS Uncaught Error: [$injector:modulerr]

https://docs.angularjs.org/error/ $injector/modulerr?p0=countriesModule&p1=%E2%80%A62Flocalhost:8080%2Fbower_components%2Fangular%2Fangular.min.js:21:19

が、残念ながらそれは私に

+0

「countriesDataModule」への参照のみが表示されます – Ozrix

+0

コード例に表示されていないcountriesModuleを参照している場所 – Austin

+0

エラー:モジュール 'countriesModule'は使用できません。しかし私は私のアプリケーションで別のモジュールcountriesDataModuleを使用します。なぜ私はそのエラーを持っていますか? –

答えて

2

を助けにはなりませんでした共有。

関連する問題