【问题标题】:NodeJS and Angular 2NodeJS 和 Angular 2
【发布时间】:2016-12-01 15:42:06
【问题描述】:

我想用 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 文件,以便我可以使用我的路线?

【问题讨论】:

    标签: node.js angular gulp webpack


    【解决方案1】:

    有一个很好的解决方案来了。但它目前处于 alpha 阶段,但您仍然可以使用它。它被称为AngularUniversal

    githubhere上提供了用 express 构建的官方启动器

    【讨论】:

      【解决方案2】:

      另一个选择是使用这个种子项目-http://matthiasschuetz.com/angular2-seed/

      这是一个基本的 Angular 2 TypeScript 入门项目,涵盖-

      • 一个路由概念(单独的路由配置文件)
      • 登录和仪表板视图组件(授权/公共路由)
      • 错误页面处理
      • 指令(表单输入)
      • 服务(授权)
      • 管道(确定活动路线)
      • 使用 es6-shim、Reflect、Rx.js 和 Zone.js

      它依赖于 TypeScript、SystemJS、Gulp 和 Sass。

      源码链接-https://github.com/matthias-schuetz/angular2-seed


      你也可以看看 Angular2 Webpack Starter。

      详情请点击此处 - https://angularclass.github.io/angular2-webpack-starter/

      源代码在这里-https://github.com/AngularClass/angular2-webpack-starter

      【讨论】:

        猜你喜欢
        • 2016-09-09
        • 2017-06-30
        • 1970-01-01
        • 2016-07-01
        • 2016-07-09
        • 2017-12-24
        • 2017-11-28
        • 2018-01-10
        • 2018-01-02
        相关资源
        最近更新 更多