我设置一个与Angular一起运行的网络应用程序已经有一段时间了。我正在通过一个旧项目(尝试在我正在执行的页面上实现控制器,确保控制器文件已正确设置等)回溯我的步骤,并且我的新项目中的所有内容与我的旧项目的方式相匹配建立。
然而,当我加载我正在尝试使用的页面时,会出现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>
控制器:
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文件,我可以让项目正常工作。
答案 0 :(得分:1)
更改您的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>