我正在使用Angular2 RC4版本和webpack开发服务器。我无法成功加载我的应用程序。在浏览器控制台上,它会抛出 404,并且无法使用 webpack 加载 AppComponent 模板文件。如果我使用精简服务器,这有效
app.component.ts 代码段
@Component({
moduleId:module.id,
selector: 'body',
templateUrl: 'app.component.html',
})
webpack.config.js snippet
module:{
loaders:[
{test:/.ts$/, loader:'ts', exclude: /node_modules/},
{test:/.html$/, loader:'html' },
],
},
错误browser_adapter.js?0526:84错误:未捕获(承诺中):无法加载/app.component.html
另一种选择是将很棒的打字稿加载器与 angular2-template-loader 结合使用,为您内联所有样式,并且您不需要 require。
https://github.com/TheLarkInn/angular2-template-loader
module: {
loaders: [
{
test: /.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader'],
exclude: [/.(spec|e2e).ts$/]
}
]
},
在 Angular2 webpack 的情况下,
像这样使用模板-
template: require('./app.component.html'),
styles: [require('./app.component.css')]
而不是
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
看看这是否有帮助。