gpt4 book ai didi

javascript - Express.js 应用程序尝试使用 Angular : Uncaught Error: [$injector:nomod] and Uncaught Error: [$injector:modulerr]

转载 作者:行者123 更新时间:2023-11-30 20:55:14 33 4
gpt4 key购买 nike

自从我设置一个与 Angular 一起运行的网络应用程序以来已经有一段时间了。我正在通过一个旧项目回顾我的步骤(尝试在我正在做的页面上实现一个 Controller ,确保 Controller 文件设置正确等),并且我的新项目中的所有内容都与我的旧项目相匹配设置。

但是,当我加载我尝试使用的页面时,会出现 2 个错误,并且当我按下按钮时,我对快速服务器的 GET 调用不会触发。这些错误是:

angular.js:38 Uncaught Error: [$injector:nomod] http://errors.angularjs.org/1.5.6/$injector/nomod?p0=eagledreamApp
at angular.js:38
at angular.js:2101
at b (angular.js:2025)
at Object.module (angular.js:2099)
at mainpageController.js:1
(anonymous) @ angular.js:38
(anonymous) @ angular.js:2101
b @ angular.js:2025
(anonymous) @ angular.js:2099
(anonymous) @ mainpageController.js:1
angular.js:38 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.6/$injector/modulerr?p0=eagledreamApp&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.5.6%2F%24injector%2Fnomod%3Fp0%3DeagledreamApp%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A6%3A412%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A25%3A235%0A%20%20%20%20at%20b%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A24%3A282)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A25%3A20%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A39%3A374%0A%20%20%20%20at%20q%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A7%3A355)%0A%20%20%20%20at%20g%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A39%3A222)%0A%20%20%20%20at%20db%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A43%3A246)%0A%20%20%20%20at%20c%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A21%3A19)%0A%20%20%20%20at%20Ac%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A21%3A332)
at angular.js:38
at angular.js:4630
at q (angular.js:322)
at g (angular.js:4591)
at db (angular.js:4513)
at c (angular.js:1777)
at Ac (angular.js:1798)
at fe (angular.js:1683)
at angular.js:31018
at HTMLDocument.b (angular.js:3197)

HTML:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mainpageStyles.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="mainpageController.js"></script>
</head>
<body ng-app="xyzApp" ng-controller="mainpageController">
<div id="search">
<button type="button" class="searchButton" ng-click="buttonpress()">Search</button>
</div>
</body>
</html>

Controller :

angular.module('xyzApp').controller('mainpageController', ['$scope', '$http', function($scope, $http){
$scope.buttonpress = function() {
$http.get('/buttonpress')
.then(function(response) {
alert(response);
});
};
}]);

server.js(当我在命令行上使用 npm server.js 时运行)

var express = require('express');
var app = express();
var fs = require('fs');
app.use(express.static(__dirname + '/Source'));
app.listen(3000, function() {
console.log("Launch successful. To access app, open your browser and insert the following URL into your address bar: http://localhost:3000/");
});
app.get('/', function (req, res) {
console.log("Loading Home Page...");
res.sendFile('/Source/mainpage.html', {root: __dirname });
});
app.get('/buttonpress', function (req, res) {
res.send("Hello World");
})

和 app.js

angular.module('xyzApp');

(我不太清楚为什么我必须有这个单独的文件,但这是我让我的其他项目工作的方式,那个项目有它自己的应用程序文件,但行是 angular.module(' abcApp', ['ngSanitize']); 而且我认为如果没有该 app.js 文件我无法让项目正常工作。

最佳答案

改变你的 app.js

来自

angular.module('eagledreamApp');

angular.module('xyzApp',[]);

在索引文件中也引用了app.js

<head>
<link rel="stylesheet" href="mainpageStyles.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="app.js"></script>
<script src="mainpageController.js"></script>
</head>

关于javascript - Express.js 应用程序尝试使用 Angular : Uncaught Error: [$injector:nomod] and Uncaught Error: [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47746095/

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