【问题标题】:Angular 2 webpack + typescript can not find root componentAngular 2 webpack + typescript找不到根组件
【发布时间】:2015-12-26 01:08:53
【问题描述】:

带有 webpack + typescript 的 Angular 2 无法找到根组件,除非应用程序入口文件的脚本标记位于自定义元素之后。

谁能告诉我这是否正在发生?

我是否在引导过程中遗漏了一组?

有没有办法在 angular 2 开始寻找路由组件元素之前等待页面加载?

不工作

<!DOCTYPE html>
<html>
  <head>
    <title>Express</title>
    <link rel='stylesheet' href='http://localhost:8080/dist/main_style.css' />
      <script src="libs/angular2-polyfills.min.js"></script>
      <script src="dist/main.bundle.js"></script>
  </head>
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>

工作中

<!DOCTYPE html>
<html>
  <head>
    <title>Express</title>
    <link rel='stylesheet' href='http://localhost:8080/dist/main_style.css' />
      <script src="libs/angular2-polyfills.min.js"></script>
      <!--<script src="dist/main.bundle.js"></script>-->
  </head>
  <body>
    <my-app>Loading...</my-app>
<script src="http://localhost:8080/dist/main.bundle.js"></script>
  </body>
</html>

'boot.ts' 文件

// Angular 2
import 'angular2/platform/browser';
import 'angular2/platform/common_dom';
import 'angular2/core';
import 'angular2/router';
import 'angular2/http';

// RxJS
import 'rxjs';

import {bootstrap}    from 'angular2/platform/browser'
import {AppComponent} from './app.component'

bootstrap(AppComponent);  

【问题讨论】:

    标签: javascript angular webpack


    【解决方案1】:

    我想这是因为当您将 webpack 包放在顶部时,所有 Angular 2 脚本都在 DOM 完全松散之前运行。这意味着 Angular 2 正在尝试启动,但 &lt;my-app&gt;&lt;/my-app&gt; 标记尚未呈现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 2016-10-04
      • 2016-06-01
      • 2017-09-07
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多