簡體   English   中英

Angular 2錯誤:(SystemJS)XHR錯誤(找不到404)

[英]Angular 2 Error: (SystemJS) XHR error (404 Not Found)

我需要通過this-> https://github.com/vimalavinisha/angular2-google-chart將Google圖表添加到我的項目中

我遵循了每個步驟,但是我從SystemJs得到了這個錯誤,我找到了一些答案(2-3個月大),但是它們對我沒有用(角度2)。

這是我的package.json

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "scripts": {
   "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/angular/angular.io/blob/master/LICENSE"
    }
  ],
  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@angular/upgrade": "~2.1.0",
    "angular-in-memory-web-api": "~0.1.5",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3",
    "typings":"^1.4.0"
  }
}

systemjs.config.js ----

(function (global) {
   System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

      // other libraries
      'rxjs':                       'npm:rxjs',
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular2-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

tsConfig.json ---

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

最后是app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';
import { GoogleChart } from 'angular2-google-chart/directives/angular2-google-chart.directive';

@NgModule({
  imports: [ BrowserModule ,GoogleChart],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

這是我遇到的錯誤->在將http:// localhost:3000 / angular2-google-chart / directives / angular2-google-chart.directive加載為“ angular2-google-chart / directives / angular2-google-chart”時出錯。指示

我找不到有效的答案,因為這個錯誤,我已經浪費了很多時間。

當我查看您共享的樣本systemjs.config.js時,它仍然缺少mappackagesdirectives屬性。

這是從github文件https://github.com/vimalavinisha/angular2-google-chart/blob/master/systemjs.config.js看到的樣子

 var map = {
    ...
    'directives' : 'directives/'
  };

  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
     ...
    'directives':{ defaultExtension: 'js' } 
  };

我自己解決了。 我已經創建了自己的指令,並從angular2-google-chart.diretive.ts文件中復制並粘貼了源代碼。 對我而言,這是唯一可行的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM