I have a Tab with many alerts, but whenever I create the second, the alert function is duplicated. Help me!
What does this mean?
When I create the first alert, I use the âpresentAlert ()â function. When I create the second alert on the same Tab, I receive a notification: âFunction âpresentAlert ()â is duplicated.â Is it possible to create more than one Alert on the same Tab?
Where is that presentAlert()
Function from?
Arenât we talking about an Ionic Alert?
yea! Itâs about ionic alert. I created an ionic buttons on the Html page and on the TS page I copied and pasted the command described on https://ionicframework.com/docs/api/alert for Usage/Angular. Like this:
constructor(public alertController: AlertController) {}
async presentAlert() {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'First step',
message: 'Open your browser.',
buttons: ['OK']
});
await alert.present();
}
,,,
When I create the second alert, Header: "Second step", I use the same command, but a notification appears and states that the constructor is duplicated and the "presentAlert ()" function too! Like this:
constructor(public alertController: AlertController) {}
**First Alert** async presentAlert() {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'First step',
message: 'Open your browser.',
buttons: ['OK']
});
await alert.present();
**Second Alert** async presentAlert() {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Second step',
message: 'Read the text',
buttons: ['OK']
});
await alert.present();
}
,,,
The buttons on the Html page are connected to the TS page by the "presentAlert ()" function. Like this:
<ion-button (click)=âpresentAlert()â>First Step</ion-button>
That way, I get a notification in VScode stating that the function âpresentAlertâ is duplicated and the constructor too. I don't know what to do because I need more than one alert of the same category. Can you help me?
Think about it from the JavaScript engineâs perspective: how is it supposed to know which of the two functions you wish to call if you have given them the exact same name?
Is it possible to create an alert function with different names? Can you help me?
I think this would be a more productive conversation if you back up and describe what youâre actually attempting to do.
To answer your direct question, of course you can create as many functions as you like and name them whatever you wish. There is no such inherent thing as âan alert functionâ.
Iâm worried, though. Tabs and alerts are both extremely popular with newcomers to web app development, and also very easy to misuse. I suspect that in the final analysis, youâll end up wanting to use neither one of them at all.
In fact, after seeing your answer, I realized that Iâm having trouble creating a module. I have many buttons with an alert function. But only one module is accepted âshowAlertâ.
When I create a new module for the next button, I get this message: âIdentifier âopenAlertII()â is not defined. The component declaration, template variable declarations, and element referencs do not contain such a member ngâ.
How can I connect my button to the alert function for a new module?
No, that isnât it either. Please forget about all the technical jargon and describe in human terms something like:
The first time a user opens my app, I want to guide them through a setup process that consists of the following steps: A, B, and then C.
The first time the user opens my app, I want it to have a page with 10 alerts. I managed to solve my problem with the method, but I find it difficult to organize more than one alert on my TSpage.
I did something like that; does not report errors, but the second alert does not open:
TSpage-
import { Component } from â@angular/coreâ;
import { AlertController } from â@ionic/angularâ;
@Component({
selector: âapp-tab1â,
templateUrl: âtab1.page.htmlâ,
styleUrls: [âtab1.page.scssâ]
})
export class Tab1Page {
constructor(public alert: AlertController) {}
async AlertOne(){
const alert = await this.alert.create({
cssClass: 'string',
header: 'Name1',
message:'Example1',
buttons: ['OK']
});
await alert.present();
}
}
export class tab1Page {
constructor(public alertI: AlertController) {}
async AlertTwo() {
const alert = await this.alertI.create({
cssClass: 'string',
header: 'Name2',
message: 'Example2',
buttons: ['Ok']
});
await alert.present();
}
}
Sorry, but I officially give up. I canât seem to break through the communication wall here and get you to explain your goal in business terms. Think of this as a user. Alerts are jarring and disruptive. Would you get through more than two or three of them before binning the app, let alone 10?
Okay, anyway, thank you very much for trying to help me. If you know how to compile more than 1 alert on the TS page, please tell me the way. My alerts are list of buttons whit information
100 alerts in a row. Plse post Youtube video of result
Then the question I would ask is:
How do I present one of 10 pieces of information to a user?
âŚand I would suggest using an accordion component, like Angular Materialâs expansion panel, as opposed to 10 alerts.
Thank you very much! I didnât know this component, it will help me a lot and save time. Thanks for your patience, Iâm starting now at Ionic.