【问题标题】:Angular Tour of Heroes Error Importing HttpClientModuleAngular 英雄之旅导入 HttpClientModule 时出错
【发布时间】:2018-05-03 05:45:06
【问题描述】:

我正在尝试 Angular 教程的入门。 https://angular.io/tutorial/toh-pt6

当我按照说明导入 HttpClientModule 时,出现以下错误。

请帮忙。我在 mac 上使用 npm。

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular/common/bundles/common.umd.js/http
Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular/common/bundles/common.umd.js/http
    at XMLHttpRequest.wrapFn (http://localhost:3000/node_modules/zone.js/dist/zone.js:1166:39)
    at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:425:31)
    at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:192:47)
    at ZoneTask.invokeTask [as invoke] (http://localhost:3000/node_modules/zone.js/dist/zone.js:499:34)
    at invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:1540:14)
    at XMLHttpRequest.globalZoneAwareCallback (http://localhost:3000/node_modules/zone.js/dist/zone.js:1566:17)
Error loading http://localhost:3000/node_modules/@angular/common/bundles/common.umd.js/http as "@angular/common/http" from http://localhost:3000/app/app.module.js
    at XMLHttpRequest.wrapFn (http://localhost:3000/node_modules/zone.js/dist/zone.js:1166:39)
    at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:425:31)
    at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:192:47)
    at ZoneTask.invokeTask [as invoke] (http://localhost:3000/node_modules/zone.js/dist/zone.js:499:34)
    at invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:1540:14)
    at XMLHttpRequest.globalZoneAwareCallback (http://localhost:3000/node_modules/zone.js/dist/zone.js:1566:17)
Error loading http://localhost:3000/node_modules/@angular/common/bundles/common.umd.js/http as "@angular/common/http" from http://localhost:3000/app/app.module.js

【问题讨论】:

    标签: angular


    【解决方案1】:

    您还应该通过添加以下内容来更改您的 systemjs 配置:

     map: {
      ...
      '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
      'tslib': 'npm:tslib/tslib.js'
    

    另见

    【讨论】:

    • 但是教程中没有。由于这是一个入门教程,我是否可以说应该有一种简单的方法来解决这个问题?还是我错过了一些说明?
    • 是的,你说得对,它不是。似乎在使用 http 时,你应该熟悉 systemjs 配置。你可以在github上问这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多