首页 > 解决方案 > 如何将计数器值传递给 AlertController 的标头

问题描述

我正在尝试将值实际传递给警报控制器的标头。出现警报,但不幸的是标题没有显示当前的 this.counter 值。

所以这是我的一段代码。请注意,函数 idleAlert() 是从构造函数启动的。

private counter: number;


  startCountdown(seconds) {
    let counter = seconds;

    const interval = setInterval(() => {
        this.counter = this.counter;
        counter--;


        if (counter < 0) {
            clearInterval(interval);
            console.log('Ding!');
        }

    }, 1000);
}

async idleAlert() {
    this.startCountdown(100);

    this.alertIdle = await this.alertController.create({
        header: 'Current counter value is: ' + this.counter,
        cssClass: 'customAlert',
        backdropDismiss: false,
        buttons: [
            {
                text: 'Logout',
                role: 'cancel',
                cssClass: 'alertBtnGrey',
                handler: (data) => {
                    this.stopWatching();
                    this.authService.logout();

                }
            }, {
                text: 'Contrinue',
                cssClass: 'alertBtnSuccess',
                handler: () => {
                    this.restartTimer();
                }
            }
        ]
    });

    await this.alertIdle.present();

}

标签: angularionic-framework

解决方案


推荐阅读