我在运行应用程序时遇到以下错误:
它似乎正在寻找./app.component
,而不是./app.component.js
这是我的 main.ts
文件:
import { bootstrap } from 'angular2/platform/browser';
import { AppComponent } from './app.component';
bootstrap(AppComponent);
我在这里配置依赖项时做错了什么?注意:如果我将引用更改为 import { AppComponent } from './app.component.js';
,那么错误就会消失,并且我在其他引用中会遇到更多相同的错误。
编辑:
其中一条评论表明我的 system.config() 可能存在问题,我认为这听起来很合理,但是,这是我的 index.html
文件的摘录,我看不出有什么问题?
...
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('client/dev/main.js')
.then(null, console.error.bind(console));
</script>
...
最佳答案
您的错误可能是:
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('client/dev/main.js')
.then(null, console.error.bind(console));
</script>
而不是
<script>
System.config({
packages: {
"client/dev": { // this line changed, here the directory where your generated `js` files are, has to be specified
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('client/dev/main')
.then(null, console.error.bind(console));
</script>
刚开始时我遇到了和你完全相同的问题;)
如果您使用最新的 Angular Beta 版本 (12),zone
错误也会消失。
关于javascript - Angular 2 不渲染带有文件扩展名的依赖链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36190849/