2017-02-02 2 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라는 두 개의 폴더와 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 
관련 문제