防爆preSS和AngularJS - 尝试打开主页时,网页冻结网页、主页、preSS、AngularJS

2023-09-14 00:11:10 作者:回不去的從前

我将尽可能详细地解释了这个问题。

I will explain the issue in as much detail as possible.

我试图用AngularJS用防爆preSS和正在运行陷入困境。我想显示HTML文件(不使用模板引擎)。这些HTML文件将具有AngularJS指令。结果不过,我不能够显示一个简单的HTML文件本身!

I am attempting to use AngularJS with Express and am running into trouble. I wish to display HTML files (not using a templating engine). These HTML files will have AngularJS directives. However, I am not able to display a simple HTML file itself!

的目录结构是如下所示:

The directory structure is as follows:

Root  
---->public  
-------->js  
------------>app.js  
------------>controllers.js  
---->views  
-------->index.html  
-------->partials  
------------>test.html  
---->app.js  

公共/ JS / app.js的内容是:

angular.module('myApp', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/', {templateUrl: 'partials/test.html', controller: IndexCtrl});
$routeProvider.otherwise({redirectTo: '/'});
}]);  

公共/ JS /控制器/ JS 的内容是:

function IndexCtrl() {  
}  

body标签的的意见/ index.html的内容是:

<div ng-view></div>  

就是这样。人们期望,AngularJS将取代与test.html的上述观点 - 的意见/谐音/ test.html的,其内容是:

This is the test page!  

段落标记之中。这就是它!

enclosed within the paragraph tags. That's it!

最后, ROOT / app.js的内容文件是:

var express = require('express');

var app = module.exports = express();  

// Configuration

app.configure(function(){  
    app.set('views', __dirname + '/views');  
    app.engine('html', require('ejs').renderFile);  
    app.use(express.bodyParser());  
    app.use(express.methodOverride());  
    app.use(express.static(__dirname + '/public'));  
    app.use(app.router);  
});

app.configure('development', function(){  
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));  
});  

app.configure('production', function(){  
  app.use(express.errorHandler());  
});  

// routes

app.get('/', function(request, response) {  
    response.render('index.html');  
});  

// Start server

app.listen(3000, function(){  
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);  
});  

现在,当我做 $节点app.js 在根文件夹,在服务器启动没有任何错误。但是,如果我去本地主机:3000 在浏览器中的URL修改本地主机:3000 /#/ 和网页卡住/冻结。我甚至无法检查控制台日志在Chrome!结果这是我面临的问题。什么我做错了任何线索?

Now, when I do $node app.js in the root folder, the server starts without any error. However if I go to localhost:3000 in the browser, the URL changes to localhost:3000/#/ and the page gets stuck / freezes. I can't even check the console log in Chrome! This is the problem that I am facing. Any clue about what I am doing wrong?

推荐答案

终于想通了 - 拉!!结果的头发很多激烈的时刻之后,为什么页面冻结的原因是因为(解释步步):

Finally figured it out - after many intense moments of hair pulling!! The reason why the page freezes is because (explained step by step):

用户推出本地主机:3000 这就要求前preSS服务器/防爆preSS呈现的index.html AngularJS将呈现模板谐音/ test.html文件。在这里,我正在胡乱猜测 - AngularJS已对页谐音/ test.html的HTTP请求。

不过,你可以看到,前preSS或者说app.js没有这个GET请求的处理程序。也就是说,下面code丢失: User launches localhost:3000 This requests the express server for '/' Express renders index.html AngularJS will render the template 'partials/test.html'. Here, I am taking a wild guess - AngularJS has made a HTTP request for the page 'partials/test.html'.

However, you can see that express or rather app.js does not have a handler for this GET request. That is, the following code is missing:

app.get('谐音/:名称',函数(请求,响应){结果变量名称= request.params.name;结果response.render('谐音/+姓名);结果});

app.get('partials/:name', function(request, response) { var name = request.params.name; response.render('partials/' + name); });

app.js 根目录。有一次,我添加此code,页面呈现预期。

inside app.js of the ROOT directory. Once I add this code, the page renders as expected.