Ionic2 Alert is popuping twice


#1

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?


#2

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


#3

This is the response : It is just an object


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

#4

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?


#5

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