Home:ALL Converter>Ionic 4 Angular AlertController message not showing in release build

Ionic 4 Angular AlertController message not showing in release build

Ask Time:2020-05-29T22:18:50         Author:Matdragon

Json Formatter

I've built a small alert service (wrapper for Angular AlertController) in my Ionic 4 project, it works perfectly when I view the project in "ionic serve" (browser), "ionic cordova emulate" (on my connected phone), "ionic cordova build android" (installing the app-debug APK manually on my phone) however when I build the release version of the app using "ionic cordova build android --prod --release" the "message" part of the Alert does not show. The header (title) and the buttons show and work fine still, but the message does not appear.

Here is my method which creates and presents the alert:

   /**
 * "Confirm" with callback or "Cancel" alert
 */
async confirmOrCancelAlert(title, message, callback) {
    const alert = await this.alertController.create({
        header: title,
        message: message,
        buttons: [
            {
                text: 'Cancel',
                role: 'cancel',
                cssClass: 'secondary',
            }, {
                text: 'Confirm',
                handler: () => {
                    callback();
                }
            }
        ]
    });

    await alert.present();
}

This is the code which called the method shown above, which is called from a button click:

    /**
 * Answer questions button event click
 */
answerQuestions() {
    if (this.shift.getEarly() && (this.shift.getTimeToStart().asHours() > environment.alertTimes.answerQuestions)) {
        var timeTo = this.durationFormatPipe.transform(this.shift.getStart());
        var message = 'Your shift starts ' + timeTo + ', are you sure you want to answer questions now?';

        this.alertService.confirmOrCancelAlert('You are early!', message, () => {
            this.doAnswerQuestions();
        });
    } else {
        this.doAnswerQuestions();
    }
}

Here are two images showing the message messing from the release build but showing in the serve / emulate / debug builds:

Release Build

Debug Build

Many thanks in advance for any and all advice.

Author:Matdragon,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/62088052/ionic-4-angular-alertcontroller-message-not-showing-in-release-build
Mahdi Zarei :

I think it's a timing problem. when you call confirmOrCancelAlert() the timeTo is not prepared yet. so the type of message will be undefined.\n\ntry this:\n\n answerQuestions() {\n if (this.shift.getEarly() && (this.shift.getTimeToStart().asHours() > environment.alertTimes.answerQuestions)) {\n var timeTo = this.durationFormatPipe.transform(this.shift.getStart());\n var message = 'Your shift starts ' + timeTo + ', are you sure you want to answer questions now?';\n\n setTimeout(() => { \n this.alertService.confirmOrCancelAlert('You are early!', message, () => {\n this.doAnswerQuestions();\n });\n }, 50);\n\n } else {\n this.doAnswerQuestions();\n }\n }\n",
2020-05-29T21:50:37
yy