Angular 在使用指令时给出 @angular/core 404 not found 错误 [英] Angular gives @angular/core 404 not found error when using directives

查看:37
本文介绍了Angular 在使用指令时给出 @angular/core 404 not found 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I add in this line of code into my @Component:

directives: [HeroDetailComponent]

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

The code breaks, and gives me this error:

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

这些是我的 index.html 中的脚本:

These are the scripts in my 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>

如果我遗漏了诊断此问题的任何信息,请告诉我,我会在此处提供.

If I'm missing out any information for diagnosing this issue, please tell me and I'll include it here.

推荐答案

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

If you want to use the RC version of Angular2, you need to configure SystemJS this way:

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 版本,在 script 元素中包含 node_modules/angular2/bundles/angular2.dev.js 文件后,请导入此包:

If you want to use beta versions, after having included the node_modules/angular2/bundles/angular2.dev.js file in a script element, import this package instead:

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

这篇关于Angular 在使用指令时给出 @angular/core 404 not found 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆