嘿,在我的angular2应用程序中,我遇到了这个错误:
Potentially unhandled rejection [3] Error loading "app" at http://localhost:8080/app.js
我使用官方示例,这里是代码:
app.js
import {Component, View, bootstrap} from 'angular2';
@Component({
selector: 'my-app'
})
@View({
template: '<h1>My first Angular 2 App</h1>'
})
class AppComponent {
}
bootstrap(AppComponent);
的index.html
<!DOCTYPE html>
<html>
<head>
<script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>
<script src="https://jspm.io/system@0.16.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.26/angular2.dev.js"> </script>
</head>
<body>
<my-app></my-app>
<script>
System.import('app');
</script>
</body>
</html>
答案 0 :(得分:2)
尝试:
import {Component, View, bootstrap} from 'angular2/angular2';
@Component({
selector: 'my-app'
})
@View({
template: '<h1>My first Angular 2 App</h1>'
})
class AppComponent {
}
bootstrap(AppComponent);
答案 1 :(得分:1)
您没有使用正确的import
声明。
将import {Component, View, bootstrap} from angular2
替换为
import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser'
检查官方Angular2快速备忘单参考here:
答案 2 :(得分:0)
从angular2@2.0.0-beta.0开始,导入的命名空间发生了变化。
import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
@Component({
selector: 'my-app'
})
@View({
template: '<h1>My first Angular 2 App</h1>'
})
class AppComponent {}
bootstrap(AppComponent);
如果您仍在使用alpha版本,则导入应为
import {Component, View, bootstrap} from 'angular2/angular2';