将angular2与nodejs集成

时间:2017-06-02 06:23:03

标签: node.js angular express

This is my file directory

我正在尝试将angular2与nodejs集成。但index.js无法找到index.html文件。有人可以请帮帮我。(PS。我是一个完全的初学者)。

index.js file

以下是我的index.html文件的代码。(此文件无法加载)

       <title>Hello World</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.6/angular2-polyfills.js"></script>
    <script src="https://code.angularjs.org/tools/system.js"></script>
    <script src="https://code.angularjs.org/tools/typescript.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.6/Rx.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.6/angular2.dev.js"></script>
    <script>
      System.config({
        transpiler: 'typescript',
        typescriptOptions: { emitDecoratorMetadata: true },
        packages: {'app': {defaultExtension: 'ts'}},
        map: { 'app': './app' }
      });
      System.import('app/hello_world_main')
            .then(null, console.error.bind(console));
    </script>
  </head>
<body>
   <my-app>Loading...</my-app>
</body>

1 个答案:

答案 0 :(得分:1)

您应该像这样设置静态文件的路径:

app.use( express.static(__dirname + '/view' ) );

来源:https://expressjs.com/en/starter/static-files.html

相关问题