angular2快速启动只显示Loading ..而不是index.html的内容

时间:2016-05-17 13:12:36

标签: node.js angular

第一次使用angular2,按照5 minute Quickstart guide的指示进行角度2。

一切运行良好,意味着在运行npm start

时没有错误

npm start image

但是当我打开

  

本地主机:3000

它显示 正在加载... 不期待的文字。根据这个例子,index.html的内容应该反映在此。

在控制台中

有错误:

EXCEPTION:TypeError:无法设置属性' endSourceSpan'为null

main.ts

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

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

bootstrap(AppComponent);

app.component.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>

请帮助我出错。

2 个答案:

答案 0 :(得分:2)

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

template : '<div</div>'

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

修改

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

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

答案 1 :(得分:0)

您应该检查终端中nodeserver节目的端口号, 在Angular2中它将在4200运行。 即** NG Live Development Server正在http://localhost:4200上运行。 ** 然后在浏览器中打开指定端口的localhost。