简单的Angular 2应用程序给出了“可能未处理的拒绝”.错误

Simple Angular 2 app gives "Potentially unhandled rejection" error

本文关键字:未处理 错误 拒绝 Angular 应用程序 简单      更新时间:2023-09-26

我有这个非常基本的例子:

index . html:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>FlyLeaf</title>
        <script src="js/lib/system.js"></script>
        <script src="js/lib/angular2.dev.js"></script>
    </head>
    <body>
        <main-app></main-app>
        <script>
            System.config({
                paths: {
                    'app.js': 'js/app.js'
                }
            });
            System.import('app.js');
        </script>
    </body>
</html>

和inside app.js:

import {Component, View, bootstrap} from 'angular2/angular2';
@Component({
    selector: 'main-app'
})
@View({
    directives: [CSSClass, NgFor],
    template: `
        <h1>My first Angular 2 App</h1>
    `
})
class MainApp {
    constructor() {
        this.footerLinks = [];
    }
}
bootstrap(MainApp);

给了我这个错误:

"Potentially unhandled rejection [3] Error loading "app.js" at http://localhost/HelloWorld/js/app.js
http://localhost/HelloWorld/js/app.js:3:1: Unexpected token @ (WARNING: non-Error used)"

我看到它在一个活塞上工作,局部它不…(

(在Firefox &Chrome)

对于我所看到的错误,您缺少可以让您使用注释的跟踪器

所以把它添加到你的HTML中(见它甚至被添加到文档6下)。声明HTML)

<script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>

和在您的系统中。添加这些选项

System.config({
    traceurOptions: {
       annotations: true,
       types: true,
       memberVariables: true
   },
//...

最后,作为建议,使用System。像这样导入

System.import("your.app").catch(console.log.bind(console));

这样你就可以捕获更多的错误。

试一试,你就可以走了