简体   繁体   English

为什么我的应用程序中的路由不起作用?

[英]Why does routing in my app doesn't work?

I use angularJS and want to add routing to my app. 我使用angularJS并想向我的应用添加路由。 But I have error: 但是我有错误:

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.

This is my file app.js: 这是我的文件app.js:

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'
    });
}]);

And file controllers.js: 和文件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 file: 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>

Structure of my project: 我的项目结构:

在此处输入图片说明

I have visited other pages and seen there some tips: 我访问了其他页面,并看到了一些提示:

AngularJS 1.2 $injector:modulerr AngularJS 1.2 $ injector:modulerr

Angular JS Uncaught Error: [$injector:modulerr] Angular JS未捕获错误:[$ injector:modulerr]

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

but unfortunately it didn't help me 但不幸的是它没有帮助我

您共享的代码中没有引用任何称为countryModule的内容。

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

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