我想制作一个计数器,当我按加减钮时数字会加减且当数字到达某一个数字(例如:5)会发出提示音
TS
Value:number=0
this.NativeAudio.preloadSimple('beep-x1','assets/audio/beep-x1.mp3').then((success) =>{
console.log("success")
},(error) =>{
console.log("error")
}
)
let Value:number=0
if(Value ==5){
this.play1()
}
play1(){
this.NativeAudio.play('beep-x1').then((success) =>{
console.log("success playing")
},(error) =>{
console.log(error)
})
}
decrement(){
this.Value++
}
increment(){
this.Value--
}
html
<button ion-button (click) ="decrement()">+</button>
<button ion-button (click) ="increment()">-</button>
{{Value}}
當我計數到5時play1()無反應,請問有人能告訴我如何解決這個問題嗎?
把
if(Value ==5){ this.play1() }
放到increment方法中后面