Ionic2 Alert is popuping twice

Hello guys, I’m trying to show an Alert after Ajax call and this Alert appear twice. I dont know what I’m doing wrong.
This is my code. I call displayWelcomeAlert() after getBlogData()

 constructor(public navCtrl: NavController, private BackEndDataService: BackEndData,
    private globalVars: GlobalVars, private alertCtrl: AlertController) {
     this.getBlogData();
  }

  displayWelcomeAlert(info) {
    var text = jsHtmlEnc.htmlDecode(info.desc);
    var websiteUrl = info.url;

    let confirm = this.alertCtrl.create({
      title: 'Message de Vie',
      message: text,
      buttons: [
        {
          text: 'Partager',
          handler: () => {
            this.share(text, websiteUrl);
          }
        },
        {
          text: 'OK',
          handler: data => {
            console.log('OK clicked');
          }
        }
      ]
    });
    confirm.present();
  }

  getBlogData() {
    this.BackEndDataService.GetBlogInfo().subscribe(
      (res) => {
        this.displayWelcomeAlert(res);
      })
  }

Can you help?

Do we know how many items are being emitted by the Observable returned by GetBlogInfo()?

This is the response : It is just an object


{
  "url": "XXXX",
  "desc": "XXXX",
  "admin_email": "XXX"
}

Hello all, I notice that it is the constructor which is executing twice.
I put only console.log() and I found that it is showing twice on the console.

  constructor(public navCtrl: NavController, private BackEndDataService: BackEndData,
    private globalVars: GlobalVars, private alertCtrl: AlertController) {
    // this.loadPosts();
    // this.getBlogData();
  console.log("called function");
  }

did someone face this error before?

Finaly I resolved my issue. The problem was that I called the forRoot() method twice. In app.component and in app.module.

Thank you all

1 Like