错误:Angular2 应用程序中的 XHR 错误(未找到 404)



我是 angularjs 的新手,并使用 angular2 开发了一个演示应用程序。 我在运行应用程序时收到以下错误。尽管下面的错误说 404,但当我在浏览器上点击带有扩展名的相同 url(即 http://localhost:4679/Binder/CustomerModuleLibrary(时 .js ,脚本确实加载到浏览器中。

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 吗?

我错过了在master.html中添加它。添加它解决了这个问题。

System.config({
       "defaultJSExtensions":true
    });

最新更新