gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:04:37 27 4
gpt4 key购买 nike

首先,我必须说,我已经查看了与我的问题相关的所有现有问题,但没有发现任何内容可以解决我的问题。

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 标签内写入 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']);
});
});

关于javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module due to:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25230752/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com