2015-08-19 10 views
2

我有这个非常简单的例子:简单的角2的应用程序提供了 “可能未处理拒绝” 错误

的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> 

和内部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)" 

我看到了它的工作在plunker,并在本地也没有... :(

(两个火狐&铬)

回答

2

对于我所看到的错误,你缺少traceur,这将让我们使用注释

因此,在你的HTML添加这个(请参阅甚至在文档中添加6. Declare the HTML下)

<script src="https://github.jspm.io/jmcriffey/[email protected]/traceur-runtime.js"></script> 

,并在您System.config添加这些选项

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

最后,作为一个建议,使用System.import这样

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

有了这个,你就可以捕捉一些更多的错误。

试一试,你应该好好去。

+0

是的,在加载traceur和config选项后 - 然后运行:)(它有语法错误,但对于app.js的第一行 - “import {Composer ...”。但它工作正常。 。:D ...) –

+1

现在语法错误消失了。我所做的是我从“lib”文件夹中下载了四个文件 - angular2.dev.js(来自#32),system.js,traceur-runtime.js和[email protected],以及使HTML从那里加载它们,现在一切正常 - 我拥有本地所有必要的功能,并且我的代码正在工作:) ... –

相关问题