2017-03-03 1 views
1

저는 Angular의 소재 디자인을 통합하려고합니다. 다음은 official documentation입니다.
나는 NPM 사용하여 compnents 및 hammerJS 설치 한 :
npm install --save @angular/material
npm install --save hammerjs
그리고에 내 나는 MaterialModulehammerjs 불렀다 app.module.ts :
Angular2 : hammerjs를 찾을 수 없습니다.

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { MaterialModule } from '@angular/material'; 

import { AppComponent } from './app.component'; 
import { HeaderComponent } from './comps/header.component'; 
import 'hammerjs'; 

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

그러나 콘솔이 나에게이 오류 제공 :

GET http://localhost:3000/hammerjs 404 (Not Found) 

나는 여기에 없는가?

+0

를? http://stackoverflow.com/questions/41322566/angular-2-could-not-find-hammerjs/41322790 –

+0

@Kinduser 예했는데 polyfills.ts 파일이 없습니다 (마지막 버전을 사용하고 있습니다.) 각도로) – SlimenTN

답변

0

단순히 JS 라이브러리라면 index.html 파일에 스크립트로 추가 할 수 있습니다.

타이핑이 있으면 일반적으로 가져 오지만, 자바 스크립트 파일은 가져 오지 않습니다. 당신의 node_modules에서

봐는 폴더와 같은 추가 : 당신이 그것을 확인 했나

<script src="node_modules/hammerjs/... .js"></script> 
+2

트릭을 해 주셔서 감사합니다. 그러나 이것이 왜 공식 문서에 언급되어 있지 않은지 !! 정말 이상합니다. – SlimenTN

+1

제가 생각하기에 어떤 프레임 워크를 사용하는지에 따라 외부 라이브러리를 추가하는 다른 방법이 있기 때문입니다. 이것은 가장 쉬운 방법이며 다음과 같은 구성 요소에서 특정 함수를 참조 할 수 있습니다. declare var functionName; 일반적으로 이러한 라이브러리를 추가하는 것이 더 좋고 권장되는 방법이라고 생각합니다. 당신이 사용하는 것에 달려 있습니다. – Bhetzie

관련 문제