【问题标题】:angular 2 app component not loadingAngular 2应用程序组件未加载
【发布时间】:2017-03-26 15:56:16
【问题描述】:

我正在做一个简单的 Angular 2 教程,但在尝试运行我的应用程序时我只是得到“加载”。 这是我的 index.html 文件

 <html>
      <head>
        <title>Angular CV </title>
        <base href="/">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="styles.css">
        <!-- 1. Load libraries -->
         <!-- Polyfill for older browsers -->
        <script src="node_modules/core-js/client/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>Still Loading...</my-app>
      </body>
    </html>

app.component.ts

从'@angular/core'导入{组件}; @零件({ 选择器:'我的应用', 模板: '' }) 导出类 AppComponent { }

完整代码:https://github.com/trinajoy/angularcv

【问题讨论】:

  • 控制台有错误吗?
  • 你应该执行 npm install reflect-metadata 和 npm install reflect-portfinder。
  • 在 chrome 开发者工具中我得到以下错误 shim.min.js:2 Uncaught SyntaxError: Unexpected token ) and for index.html localhost/:18 Uncaught ReferenceError: System is not defined(…) System.import('app').catch(function(err){ console.error(err); });和directive_normalizer.js:92未捕获错误:模板解析错误:(...)-但我不确定它指的是代码的哪一部分...
  • 从您的 github 存储库中,我认为您缺少 systemjs.config.js
  • 好的,我刚刚将 systemjs.config.js 添加到项目中,但应用程序仍然无法正常加载。它只是从我的 index.html 文件中读取加载...

标签: javascript angular


【解决方案1】:

Angular-clibeta.14 以来将他们的系统从 SystemJS 更改为 Webpack。不过,您似乎仍在使用 SystemJS。

您可以按照these instructions 迁移到 Webpack。但是,由于您只是在学习教程,因此我建议您 install angular-cli from scratch

【讨论】:

  • 好吧,我做了以下 npm uninstall -g angular-cli,npm cache clean,npm install -g angular-cli@latest,然后重新开始,但据我所见,我有相同的信息在我的 json 文件和 angular-cli json 中,我仍然到达同一点,我的应用程序只显示来自索引文件的“加载”.. 此处的完整代码:github.com/trinajoy/angulartest.git 我在许多教程中都有同样的问题我正在尝试
  • 但您仍在尝试在您的 index.html 中导入 SystemJS(第 17-19 行)(并且还尝试加载 SystemJS 脚本)。
  • so im donig - npm uninstall -g angular-cli,npm cache clean,npm install -g angular-cli@latest - 仍然没有获得 beta 14..?我做得不对吗?
  • 实际上我认为更改了 index.html 以匹配我正在做的教程..我想这就是问题所在..
猜你喜欢
  • 2017-01-19
  • 2016-10-25
  • 2017-11-15
  • 1970-01-01
  • 2016-08-07
  • 2018-07-05
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
相关资源
最近更新 更多