I tried to implement an ion-alert which is showed when I set [isOpen] to true. This works fine when I start my app with the CLI “ionic serve” on my browser.
But when I “capacitor” the thing to build an android app and launch it via Android Studio, the alert does not want to show on both the emulator and a physical device. On both (emulator and device) I used the “chrome://inspect” debugger. I can see in the HTML the ion-alert object, so it has been integrated properly but can’t find the option that makes/prevents it from showing.
This is my HTML (obviously ) :
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>Garage door remote</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<div class="flex-center">
<ion-button (click)="toggleGarageDoor()" shape="round" size="large" color="success">Open/Close</ion-button>
</div>
<ion-alert
[isOpen]="alertOpened"
header="Alert"
subHeader="Server connection error"
message="Can't establish connection to the server. Please quit and launch the app again"
(willDismiss)="handlingAlertDismiss()"
[buttons]="alertButtons"
backdropDismiss="false"
></ion-alert>
</ion-content>
And this is my TS associated :
import { Component, OnInit } from '@angular/core';
import { Websocket, WebsocketBuilder } from 'websocket-ts';
@Component({
selector: 'app-remote',
templateUrl: './remote.page.html',
styleUrls: ['./remote.page.scss'],
})
export class RemotePage implements OnInit {
/* Public properties */
connectionSucceeded: boolean;
alertOpened: boolean;
alertButtons: string[];
/* Private properties */
private _ws: Websocket;
/* Constructor */
constructor() {
this.alertButtons = ['Quit'];
this.alertOpened = false;
this.connectionSucceeded = false;
this._ws = new WebsocketBuilder('ws://myserver:myport')
.onOpen((i, ev) => this.handlingWsOpening(i, ev))
.onError((i, ev) => this.handlingWsError(i, ev))
.build();
}
/* Methods */
ngOnInit(): void {
}
handlingWsOpening(i: Websocket, ev: any): void {
this.connectionSucceeded = true;
}
handlingWsError(i: Websocket, ev: any): void {
this.connectionSucceeded = false;
this.alertOpened = true;
}
handlingAlertDismiss(): void {
this.alertOpened = false;
}
toggleGarageDoor() {
this.alertOpened = true;
}
}
This code works just fine on browser.
Edit : I just tried to use the basic “trigger” keyword in “ion-alert” triggering on the “ion-button” and this method works… So it appears that I’m doing something wrong with the “isOpen” keyword.
Thanks for your help.