2016-06-11 44 views
2

在Angular1中,我能夠爲ng-model添加添加去抖時間。angular2,指令輸入OnChanges延遲(去抖動)?

在Angular2中,我們可以檢測到所有input的變化。每次輸入更改是否可能有一些去抖動時間?

從以下plunker示例http://plnkr.co/edit/JKYSek?p=preview中,我輸入「hello world」,但它對每一個關鍵筆畫都有反應。

是否有可能在沒有任何編程的情況下每次更改都會有一些延遲?

import { Directive, OnChanges } from "@angular/core"; 

@Directive({ 
    selector: '[my-directive]', 
    inputs: [`myInput`] 
}) 
export class MyDirective implements OnChanges { 

    ngOnChanges(changes: {[key: string]: SimpleChange}) { 
    console.log('changes :'+ changes.myInput.currentValue); 
    } 
} 

enter image description here

回答

3

角不提供任何內容。這是討論,並有一個公開的問題AFAIR。

作爲解決方法,您可以轉發到observable或使用Observable.fromEvent()debounce