所以,我有一个带有登录按钮的欢迎页面,它加载了一个基于 Angular Js 构建的模态表单。当我在 Google Chrome 上将 welcome.html 页面作为独立页面运行时,它工作正常。
现在,我创建了一个 Express Js 框架项目并将 .html 修改为 .ejs 并将它们添加到 View 中,然后启动 Node 服务器,它将完美加载 welcome.ejs 页面。
但是,当我点击登录按钮时,它会在控制台中抛出以下错误。
angular.js:11756 GET http://localhost:3000/views/login-popup.ejs 404 (Not Found)
angular.js:11756 GET http://localhost:3000/views/login-popup.ejs 404 (Not Found)(anonymous function) @ angular.js:11756m @ angular.js:11517g @ angular.js:11227(anonymous function) @ angular.js:15961$eval @ angular.js:17229$digest @ angular.js:17045$apply @ angular.js:17337(anonymous function) @ angular.js:25023Qf @ angular.js:3456d @ angular.js:3444
angular.js:13550 Error: [$compile:tpload] http://errors.angularjs.org/1.5.5/$compile/tpload?p0=%2Fviews%2Flogin-popup.ejs&p1=404&p2=Not%20Found
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:6:412
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:156:158
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:130:226
at n.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:144:467)
at n.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:142:47)
at n.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:145:249)
at l (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:97:55)
at H (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:101:190)
at XMLHttpRequest.u.onload (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:102:229)
这就是我的 Angular 加载模式的方式
app.controller('LoginController',['$scope','$uibModal', function($scope,$uibModal){
$scope.name = 'a100';
$scope.loginModal = function(){
var modalInstance = $uibModal.open({
animation: 'true',
templateUrl: '/views/login-popup.ejs',
controller: 'LoginModalController'
});
};
}]);
Node 代码:
app.get('/',function(res,req){
res.render('welcome');
});
var server = app.listen(3000);
console.log("Server Started at port 3000");
我是 Node 和 Angular 的新手,也是 Express 框架的新手。你能在这里指导我吗?
感谢您的宝贵时间。
P.S:我也试过删除 /views
。
最佳答案
看来你还没有公开你的静态文件(css,js)。
This article解释如何使用 express 执行此操作。
这是快速入门的代码(从文章中复制粘贴)
app.use(express.static('public'));
这样做的目的是将 public 文件夹公开给网络。
Express looks up the files relative to the static directory, so the name of the static directory is not part of the URL.
关于javascript - 使用 Angular js、Node js 服务器和 express js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37560656/