如何在Express.js中将Angular 2应用添加为视图

How to add an Angular 2 App as a view in Express.js

本文关键字:应用 添加 视图 Angular 中将 Express js      更新时间:2023-09-26

我正在用Angular 2制作一个应用程序,需要从服务器上运行的脚本中获取数据。为了做到这一点,我试图将我已经存在的Angular应用程序作为视图添加到express应用程序中,就像这里所做的那样。我遵循了教程中概述的文件夹结构的初始设置说明,但教程并没有介绍如何实际连接Angular和express应用,以便在使用npm start时它们能一起运行。

然后我发现了另一个帖子,建议使用express/angular生成器,我最终安装了它,产生了这个包。json文件:

{
  "name": "support-dashboard",
  "version": "0.0.0",
  "dependencies": {
    "express": "~3.0.0",
    "ejs": "~0.8.4"
  },
  "devDependencies": {
    "connect-livereload": "~0.2.0",
    "grunt": "~0.4.1",
    "grunt-concurrent": "~0.3.0",
    "grunt-contrib-clean": "~0.4.1",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-compass": "~0.3.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-connect": "~0.3.0",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-cssmin": "~0.6.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.1.4",
    "grunt-contrib-jshint": "~0.6.0",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-watch": "~0.4.0",
    "grunt-google-cdn": "~0.2.0",
    "grunt-karma": "~0.4.3",
    "grunt-ngmin": "~0.0.2",
    "grunt-open": "~0.2.0",
    "grunt-rev": "~0.1.0",
    "grunt-svgmin": "~0.2.0",
    "grunt-usemin": "~0.1.11",
    "jasmine-core": "^2.4.1",
    "karma": "^1.1.2",
    "karma-jasmine": "^1.0.2",
    "karma-phantomjs-launcher": "^1.0.1",
    "matchdep": "~0.1.2",
    "phantomjs-prebuilt": "^2.1.11"
  },
  "engines": {
    "node": ">=0.8.0"
  },
  "scripts": {
    "test": "karma start test''karma.conf.js"
  }
}

尽管这个包打算在Express之上提供Angular的设置,但这个文件只是为Express而不是Angular设置的。在Express中建立Angular 2项目的官方方式是什么?

我打赌官方的方法是使用角通用。允许您减轻搜索引擎优化问题与一页应用程序。https://universal.angular.io/