未捕获错误:[$injector:modulerr]实例化模块失败,原因是:

Uncaught Error: [$injector:modulerr] Failed to instantiate module due to:

本文关键字:失败 模块 实例化 modulerr 错误 injector      更新时间:2023-09-26

首先我得说我已经找遍了所有与我的问题相关的问题,但是我没有找到任何解决我的问题的方法。

Uncaught Error: [$injector:modulerr] Failed to instantiate module Arrows due to:
Error: [$injector:nomod] Module 'Arrows' is not available! You either misspelled the         
module     name or forgot to load it. If registering a module ensure that you specify ...    
<omitted>...2) 
我的index . html

:

<html ng-app='Arrows'>
    <head>
        <title>Arrows</title>
        <script data-main="app" src="modules/require.js"></script>
        <link rel="stylesheet" type="text/css" href="styles/style.css">
        <script src="modules/angular-1.2.21/angular.js"></script>
        <script src="modules/angular-1.2.21/angular-route.js"></script>
    </head>
    <body ng-controller='menuController'>       
        <div ng-view>
            {{ message }}
        </div>  
    </body>
</html>
我app.js

:

define([
    './controller/menu',
    './controller/game'
], function( 
    menu,
    game
) {
    var Arrows = angular.module('Arrows', ['ngRoute']);
    Arrows.config(function($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl : 'pages/menu.html',
                controller  : 'menuController'
            })
            .when('/game', {
                templateUrl : 'pages/game.html',
                controller  : 'gameController'
            })
            .otherwise( {
                redirectTo: '/', 
                controller: 'menuController'
            }); 
    });
    Arrows.controller('gameController', function($scope) {
        $scope.message = 'hello! Its working!';
    });
    Arrows.controller('menuController', function($scope) {
        $scope.message = 'hello! Its working!';
    });
});

不知道在那里做什么。我的意思是,我加载了angular-route.js,关于这个错误的大多数问题的答案是什么?我确保在html-tag内写ng-app='Arrows'

当你使用require.js时,你必须以一种特殊的方式引导你的AngularJS应用程序。阅读这篇文章- https://www.startersquad.com/blog/angularjs-requirejs/-并尝试将其中描述的内容结合到您的具体案例中。

最后你会使用像

这样的东西
define([
   'require',
   'angular'
], function (require, ng) {
    'use strict';
    require(['domReady!'], function (document) {
       ng.bootstrap(document, ['Arrows']);
   });
});