私は試験アプリを作成しているので、時間がたつと、時間を超過した結果をユーザーに伝えて結果ページに表示するために、 !ANGULAR:Timerから退会した後に別の機能を注入するObservable
しかし、タイマーから退会した後、私の機能はループに入ります!
私はこれで助けが必要です。
マイコード!
minutesDisplay: number = 0;
hoursDisplay: number = 0;
secondsDisplay: number = 0;
sub: Subscription;
showAlert() {
let alert = this.alertCtrl.create({
subTitle: 'Ooops, Time Up! ',
});
alert.present();
this.activity.openModal();
}
ngOnInit() {
this.startTimer();
}
public ngOnDestroy() {
if (this.minutesDisplay == 1){
this.sub.unsubscribe();
}
return true;
}
private startTimer() {
let timer = Observable.timer(1, 1000);
this.sub = timer.subscribe(
t => {
this.ticks = t;
this.secondsDisplay = this.getSeconds(this.ticks);
this.minutesDisplay = this.getMinutes(this.ticks);
this.hoursDisplay = this.getHours(this.ticks);
this.ngOnDestroy();
}
);
this.showAlert();
}
あなたがplunkerを設定することができ、どのようにループを参照してください?アラートは常に表示されますか? – Vega
はい、ここではプランナーが非常に役立ちます。それ以外の場合は、構文を推測しています。 – DeborahK