我想使用nodeJS和angular2作为客户端框架创建应用程序。例如我有路线:
app.get('/', function(req, res){
res.render('home');
});
app.get('/about', function(req, res){
res.render('about');
});
app.get('/dash', function(req, res){
res.sendFile(__dirname + 'path-to-angular2-index-file.html');
});
app.listen(3000);
但是 Angular2 教程没有涵盖这样的内容,而 agular-cli 有自己的方法:Generating and serving an Angular2 project via a development server
我有以下文件夹结构:
NodeJSWebsite
--node_modules
--public
--|--img
--|--css
--|--js
--|--templates
----|--home.hbs
----|--about.hbs
--server.js
--package.json
有没有一种好的、简单的方法来编译/构建 Angular2 应用程序并渲染 html 文件,以便我能够在我的 route 使用?
最佳答案
有一个很好的解决方案即将出现。但它目前处于 alpha 阶段,但您仍然可以使用它。它的名字叫AngularUniversal 。
github上有使用express构建的官方starter here
关于node.js - NodeJS 和 Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38616180/