2017-02-02 20 views
1

私はこれを(https://www.thepolyglotdeveloper.com/2016/01/include-external-javascript-libraries-in-an-angular-2-typescript-project/)外部ライブラリをインポートするに従っています。しかし、私はそれを同じように模倣することはできません。次のエラーが発生しました。angular2で外部ライブラリをインポートするには?

GET http://127.0.0.1:8080/src/rxjs/Subject 404(見つからない)

src、folder内には、appとjsの2つのフォルダと2つのファイルindex.htmlとtsconfig.jsonがあります。

App.ts

declare var jsSHA: any; 

@Component({ 
    selector: "my-app", 
    templateUrl: "app/app.html", 
    directives: [] 
}) 

class App { 

    shaObj: any; 
    hash: String; 

    constructor() { 
     this.shaObj = new jsSHA("SHA-512", "TEXT"); 
     this.shaObj.update("This is a test"); 
     this.hash = this.shaObj.getHash("HEX"); 
    } 

} 

bootstrap(App, []); 

app.html

<h1>SHA-512 Hash</h1> 

<p>String: This is a test</p> 
<p>HEX: {{hash}}</p> 

Index.htmlと

<html> 
    <head> 
     <title>Angular 2 QuickStart</title> 
     <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> 
     <script src="js/sha.js"></script> 
     <script> 
      System.config({ 
       packages: {'app': {defaultExtension: 'js'}} 
      }); 
      System.import('app/app'); 
     </script> 
    </head> 
    <body> 
     <my-app>Loading...</my-app> 
    </body> 
</html> 

system.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', 
      'underscore': 'node_modules/underscore/underscore.js' 
     }, 
     // packages tells the System loader how to load when no filename and/or no extension 
     packages: { 
      app: { 
       main: './app.js', 
       defaultExtension: 'js' 
      }, 
      rxjs: { 
       defaultExtension: 'js' 
      } 
     } 
    }); 
})(this); 

誰かがこの問題について何か手掛かりがある場合は、私に助言してください。 guide fo this

それは外部のライブラリがある場合は、通常のNPMパッケージとしてインストール:あなたのsha.jsはあなた自身の書かれたモジュールがある場合

+0

'rxjs/Subject'をインポートする' ts'ファイルはどこかのように見えますが、SystemJsによって正しく設定されていません。 – Shawn

+0

インポートはどういう意味ですか? –

+0

いいえ、どこでもrxjsをエクスポートしません。 app.tsとapp.htmlは、私がこのプロジェクトに含まれているすべてのファイルです。 –

答えて

0

、アプリでそれをインポートするためにsha.d.tsファイルを追加する必要があります

npm install —save sha 
関連する問題