防爆preSS和AngularJS - 尝试打开主页时,网页冻结 [英] Express and AngularJS - web page freezes when attempting to open home page

查看:119
本文介绍了防爆preSS和AngularJS - 尝试打开主页时,网页冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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):


  1. 用户推出本地主机:3000

  2. 这就要求前preSS服务器/

  3. 防爆preSS呈现的index.html

  4. AngularJS将呈现模板谐音/ test.html文件。

  5. 在这里,我正在胡乱猜测 - AngularJS已对页谐音/ test.html的HTTP请求

  6. 不过,你可以看到,前preSS或者说app.js没有这个GET请求的处理程序。也就是说,下面code丢失:

  1. User launches localhost:3000
  2. This requests the express server for '/'
  3. Express renders index.html
  4. AngularJS will render the template 'partials/test.html'.
  5. Here, I am taking a wild guess - AngularJS has made a HTTP request for the page 'partials/test.html'.
  6. 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.

这篇关于防爆preSS和AngularJS - 尝试打开主页时,网页冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆