2016-03-21 30 views
1

所以我想調用'this.breakCheck();'超時完成後。現在我用每次迭代調用它,並且我的程序正在運行,但理想情況下,我希望在超時完成後僅調用一次。如何在超時完成後調用函數?超時是由點擊事件觸發的(Typescript)

public startBreak(){ 
    for(let i = this.breakSeconds; i > 0; i--){ 
    this.$timeout(() =>{ this.breakSeconds -= 1; this.breakCheck();}, 1000 * i); 
    } 
} 

以前我在這裏

public startBreak(){ 
    for(let i = this.breakSeconds; i > 0; i--){ 
     this.$timeout(() =>{ this.breakSeconds -= 1;}, 1000 * i); 
    } 
    this.breakCheck(); 
} 

了,而是因爲 'startBreak()' 是由點擊事件調用,它只是馬上跑。

謝謝!

回答

0

規格:

  • breakCheck只調用一次
  • 後,才breakSeconds

Simples稱爲:

public startBreak(){ 
    this.$timeout(()=>this.breakCheck(), this.breakSeconds * 1000); 
} 
相關問題