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

7 浏览
0 Comments

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

我使用AngularJS并想在我的应用程序中添加路由。但是我遇到了错误:

Uncaught Error: [$injector:modulerr] 无法实例化模块countriesModule,原因是:
Error: [$injector:nomod] 模块'countriesModule'不可用!您可能拼写错误或忘记加载它。如果要注册一个模块,请确保您将依赖项指定为第二个参数。

这是我的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'
    });
}]);

以及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文件:




    
    
    
    
    
    
    
    Document


    

旅行的国家

我的项目结构:

enter image description here

我访问了其他页面并找到了一些提示:

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
0 Comments

问题原因:代码中没有对countriesModule进行任何引用。

解决方法:在代码中添加对countriesModule的引用。

文章内容如下:

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

在你分享的代码中,没有任何关于countriesModule的引用。这可能是导致你的应用程序路由不起作用的原因之一。要解决这个问题,你需要在代码中添加对countriesModule的引用。

示例代码:

import { countriesModule } from '路径/countriesModule';

通过添加这行代码,你可以确保你的应用程序正确引用了countriesModule,并且路由可以正常工作了。希望这对你有帮助!

0