Angular 在使用指令时给出 @angular/core 404 未找到错误

Angular gives @angular/core 404 not found error when using directives

当我将这行代码添加到我的 @Component:

directives: [HeroDetailComponent]

代码中断,并给我这个错误:

GET http://localhost:3000/@angular/core 404 (Not Found)

这些是我的脚本 index.html:

<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>   

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>

如果我遗漏了诊断此问题的任何信息,请告诉我,我会在此处添加。

如果要使用Angular2的RC版本,需要这样配置SystemJS:

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',
];

packageNames.forEach(function(pkgName) {
  packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});

var config = {
  map: map,
  packages: packages
}

System.config(config);

如果您想使用 beta 版本,请在 node_modules/angular2/bundles/angular2.dev.js 文件包含在 script 元素中之后,改为导入此包:

import {Component, Directive, ...} from 'angular2/core';

改变这个

import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api'; 

至 ->>

import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api/in-memory-backend.service';

在你的main.ts

我在尝试按照 https://angular.io/docs/ts/latest/tutorial/toh-pt3.html 上的 Angular 2 教程时遇到了同样的错误。

但是我发现问题是我在app.component.ts中打错了,第一行应该是:

import { Component } from '@angular/core';

可是我写了'core'的大写字母:

import { Component } from '@angular/Core'

所以我的建议是确保在尝试修改 SystemJS 之前写下正确的资源名称。