node.js - angular2 quick start 只显示 Loading .. 而不是 index.html 的内容

标签 node.js angular

第一次使用 angular2 ,按照 5 minute Quickstart guide 的说明进行操作对于 Angular 2。

一切正常,意味着运行 npm start 时没有错误

npm start image

但是当我打开

localhost:3000

它显示 Loading... 不期望的文本。根据此示例,index.html 的内容应反射(reflect)这一点。

控制台出现错误:

异常:TypeError:无法将属性“endSourceSpan”设置为 null

主.ts

import { bootstrap } from '@angular/platform-browser-dynamic';

import { AppComponent } from './app.component';

bootstrap(AppComponent);

应用程序组件.ts

import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: 'My first Angular 2 App</h1>'
})

export class AppComponent {}

index.html

<html>
  <head>
    <title>Angular 2 QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">

    <!-- 1. Load libraries -->
     <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>

    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>

    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
  </head>

  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>

请帮我看看哪里出了问题。

最佳答案

我认为您的主要组件的模板有问题。例如,未正确关闭的 HTML 元素:

template : '<div</div>'

有关详细信息,请参阅此问题:

编辑

问题是您的 h1 不正确(没有 begin 元素):

@Component({
  selector: 'my-app',
  template: '<h1>My first Angular 2 App</h1>' // <------
})
export class AppComponent {}

关于node.js - angular2 quick start 只显示 Loading .. 而不是 index.html 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37277205/

相关文章:

android - 从 Facebook/Instagram 链接时,Angular 7 网站在 android WebView 上崩溃

Angular 5 HttpInterceptor 并在 header 中发送授权 token

javascript - Node.js 和 Backbone.js 的集成

javascript - Sublime Text 2 中的 Node.js 构建系统

javascript - memcache 出现 ECONNREFUSED 错误

从第 n 个子级 2 到父级的 Angular 输出变量

javascript - 将从服务器获取的数据处理成 html 文件(使用 Node.js 和 Express)

node.js - 代表用户发送消息以响应内联键盘的电报?

html - 带按钮的 Angular 隐藏

javascript - 注销 session Angular2 NodeJS