我是angularjs的新手,并使用angular2开发了一个演示应用程序。 运行应用程序时出现以下错误。虽然以下错误显示为404,但当我在浏览器上使用扩展名.js点击相同的URL(即http://localhost:4679/Binder/CustomerModuleLibrary)时,脚本会被加载到浏览器中。
Here is the error:
Error: Error: XHR error (404 Not Found) loading http://localhost:4679/Binder/CustomerModuleLibrary
at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:4679/node_modules/zone.js/dist/zone.js:698:29)
at ZoneDelegate.invokeTask (http://localhost:4679/node_modules/zone.js/dist/zone.js:265:35)
at Zone.runTask (http://localhost:4679/node_modules/zone.js/dist/zone.js:154:47)
at XMLHttpRequest.ZoneTask.invoke (http://localhost:4679/node_modules/zone.js/dist/zone.js:335:33)
Error loading http://localhost:4679/Binder/CustomerModuleLibrary as "./CustomerModuleLibrary" from http://localhost:4679/UI/startup/../../Binder/Startup.js
CustomerModuleLibrary.ts的代码
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {CustomerComponent} from './CustomerComponent';
import {FormsModule} from '@angular/forms'
@NgModule({
imports: [BrowserModule,FormsModule],
declarations: [CustomerComponent],
bootstrap: [CustomerComponent]
})
export class CustomerModuleLibrary { }
Startup.ts代码
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {CustomerModuleLibrary} from './CustomerModuleLibrary';
const platform = platformBrowserDynamic();
platform.bootstrapModule(CustomerModuleLibrary);
在systemjs.config.js文件中,
packages: {
app: {
main: '../../Binder/Startup.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
另外,我应该在运行应用程序之前执行npm start吗?
答案 0 :(得分:0)
我错过了在master.html中添加这个内容。添加它解决了这个问题。
System.config({
"defaultJSExtensions":true
});