使用指令时Angular会提供@ angular/core 404找不到错误 [英] Angular gives @angular/core 404 not found error when using directives

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

问题描述

当我将这行代码添加到我的@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中的脚本:

<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找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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