【问题标题】:angular2 quick start only showing Loading .. not the content of index.htmlangular2 快速入门仅显示正在加载 .. 而不是 index.html 的内容
【发布时间】:2016-09-13 14:49:13
【问题描述】:

第一次使用 angular2 ,遵循 5 minute Quickstart guide 的 angular 2 指令。

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

npm start image

但是当我打开时

本地主机:3000

它显示 Loading... 文本,这是不期望的。根据这个例子 index.html 的内容应该反映在这个上。

在控制台有错误:

例外: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>

请帮我解决问题。

【问题讨论】:

  • 你能提供你的主要组件的代码吗?谢谢!
  • 好的,谢谢! app.component.ts 文件呢?
  • 也许这是相关的:stackoverflow.com/a/37070952/1961059(也错误地关闭了标签/错别字)
  • 我已经在问题中添加了代码。

标签: node.js angular


【解决方案1】:

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

template : '<div</div>'

查看此问题了解更多详情:

编辑

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

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

【讨论】:

  • 感谢您的快速回复。但是你可以看到模板中没有 div
  • 是的。` h1` 标签未打开。非常感谢伙计。为什么 Angular 2 给出奇怪的错误,或者我无法正确调试错误。
  • 不客气!我认为 Angular 团队正在努力改进这一点 ;-)
  • 这个问题上下文中的另一个查询。我现在已经安装了typings 而没有-g,如果我想在全球范围内制作它,而不是我需要更早地删除或任何解决此问题的方法来在全球范围内制作包。
【解决方案2】:

您应该检查终端中显示的节点服务器的端口号, 在 Angular2 中,它将在 4200 中运行。 ie ** NG Live Development Server 正在http://localhost:4200 上运行。 ** 然后在浏览器中打开具有指定端口的 localhost。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 2022-01-14
    相关资源
    最近更新 更多