2017-03-16 2 views
2

나는 angular2 응용 작업을하고 있습니다. 나는 textarea를 autosize하기위한 요구 사항을 가지고있다. 내가 읽어보기를 이어 https://github.com/stevepapa/angular2-autosizeangular2의 텍스트 크기를 자동으로 조정하십시오.

에서 angular2 - 자동 크기 조정을 재사용하기 위해 노력하고 있어요,하지만 아래의 오류를 얻고있다

catch되지 않은 오류 : 모듈 빌드 실패 : 오류 : ENOENT : 그런 파일이나 디렉토리를 열고 ' C : \ Users \ Vipin \ SampleApp \ node_modules \ angular2-autosize \ angular2-autosize.js '를 입력하십시오.

이 문제를 해결하는 방법을 제안하십시오.

답변

5

오늘 같은 문제가 있었지만 해결되었습니다!

그래서 ... 그것은 약간의 차이이기 때문에, 당신은 단지 모듈 지시어하지 가져, 코드에서 다음

npm install https://github.com/chrum/angular2-autosize.git --save 

그리고 : https://github.com/chrum/angular2-autosize

PR 병합 될 때까지 시도 : 내 포크를 확인하시기 바랍니다 대신 :

import {Autosize} from 'angular2-autosize'; 

@NgModule({ 
    ... 
    declarations: [ 
    Autosize 
    ] 
    ... 
}) 

당신은이 있어야합니다

import {AutosizeModule} from 'angular2-autosize'; 

@NgModule({ 
    ... 
    imports: [ 
    AutosizeModule 
    ] 
    ... 
}) 
4

당신이 이런 식으로 할 수있는 패키지를 사용하지 않고. 이 작동하지만

autogrow(){ 
    let textArea = document.getElementById("textarea")  
    textArea.style.overflow = 'hidden'; 
    textArea.style.height = '0px'; 
    textArea.style.height = textArea.scrollHeight + 'px'; 
} 

아래 및 HTML처럼 아래

<textarea id="textarea" (keyup)="autogrow()" ></textarea> 
+4

같은 간단한

에서 컨트롤러, 그것은 (즉, 직접 DOM을 조작하지 마십시오) 각도의 철학을 나누기. document.getElementById를 사용하는 대신 @ViewChild를 사용하여 텍스트 영역에 대한 참조를 가져옵니다 (이후 구성 요소의 모든 자식이므로) – rmcsharry

관련 문제