2017-09-14 11 views
0

私はこのキーダウンに問題があります。キーダウンが長すぎると約束してください

私は画像をレンダリングするために角度を使用します。 keydownを押したままにしたとき。私のレンダリングメソッドがkeydownイベントのfireより速く実行されないように、keydownのfireイベントが連続している可能性があります。

これは私のコード

@HostListener('window:keydown', ['$event']) 
 
    onKeyDown(event: KeyboardEvent) { 
 
    if (CommonVariables.isFullImage) { return; } 
 

 
    /// case increase slice value. 
 
    if (event.keyCode === CommonVariables.keycodePagingDown && this._isActivePanel) { 
 
     let lastImage = this.currentTileLayout + this.currentSlice; 
 
     if (this.currentSlice < this.maxListImage && lastImage < this.maxListImage) { 
 
     this.currentSlice++; 
 

 
     let tileInfo; 
 
     this.tileViewChildern.forEach((component, index) => { 
 
      tileInfo = this._tileList[this.currentSlice + index].Clone(); 
 
      tileInfo.listIndex = this.currentSlice + index; 
 
      tileInfo.index = this._panelIndex + (index + 1); 
 
      component.changeTileSlice(tileInfo); 
 
     }); 
 
     } 
 
    } 
 
    // case decrease slice value. 
 
    else if (event.keyCode === CommonVariables.keycodePagingUp && this._isActivePanel) { 
 
     if (this.currentSlice > 0) { 
 
     this.currentSlice--; 
 

 
     let tileInfo; 
 
     this.tileViewChildern.forEach((component, index) => { 
 
      tileInfo = this._tileList[this.currentSlice + index].Clone(); 
 
      tileInfo.listIndex = this.currentSlice + index; 
 
      tileInfo.index = this._panelIndex + (index + 1); 
 
      component.changeTileSlice(tileInfo); 
 
     }); 
 
     } 
 
    } 
 
    }

であるiは、フローの実行コードを処理するための約束を使用することはできますか?

誰かが私のメソッドの終了後にkeydown fireイベントを処理する方法を教えてください。

多くのお礼ありがとうございます

答えて

0

このような状況では観測可能です。あなたのオペレータは、あなたの状況オペレータに完全に合ったdebounce timeです。オペレータは、前の2秒後にのみ値を取ることができます。それでジャムキーは無視されます。

Observable.from(event).debounceTime(2000).subscribe((event)=>ここにロジック)

関連する問題