我在加載組件時遇到問題。當我去加載另一個組件,我收到以下錯誤XHR錯誤(404)未找到Angular 2
localhost/:22 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/app/player-detail.component.ts.js(…)
我app.component.ts:
import { Component } from '@angular/core';
import { PlayerDetailComponent } from './player-detail.component.ts';
@Component({
selector: "my-app",
templateUrl: 'app/views/app.component.html',
directives: [PlayerDetailComponent],
})
export class AppComponent {
title = "title";
}
其中根據tutorial,相貌端正
我main.ts :
import { bootstrap } from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
和我的球員detail.component.ts:
import { Component } from '@angular/core';
import { Player } from './classes/player';
@Component({
selector: "player-details",
template: `<h2>Hello</h2>`,
})
export class PlayerDetailComponent {
player: Player = {
id: 1,
name: "Test Player",
email: "[email protected]",
level: 0,
maxHealth: 100,
health: 100,
maxEnergy: 100,
energy: 100,
fun: 1,
skill: 1,
knowledge: 1
};
}
和我system.config.js:
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'@angular': 'node_modules/@angular'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade',
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
map: map,
packages: packages
}
// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) { global.filterSystemConfig(config); }
System.config(config);
})(this);
我剛纔一直都在教程和改變一些變量名,我真的不知道爲什麼這個錯誤是雨後春筍般冒出來,我可以似乎沒有找到關於在線錯誤的很多信息。
感謝。始終是小事情 – ReallyGoodPie
一直髮生在我身上:) – sourdoughdetzel