0

i am very new in ionic and ,i got error while calling a function of another function in handler,I got the error this.deletMessage is not a function here is the code :

    import { Component } from '@angular/core';
import { NavController ,ActionSheetController , AlertController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public navCtrl: NavController, public alertCtrl:AlertController, public actionCtrl:ActionSheetController) {

  }

  alert(content){
    let alert = this.alertCtrl.create({
        title: "alert",
        subTitle: content,
        buttons: ["ok"]
    });
    alert.present();
  }

  actionSheet(){
    let actionSheet = this.actionCtrl.create({
      title : 'Action List',
      buttons : [{
          text : 'Delete',
          role  : 'destructive',
          handler: function(){
            this.deletMessage("you just click on delete button");
          }
      },{
            text : "edit",
            role  : 'Delete',
            handler : function(){
              console.log("hello");
            }
          }]
    }); 
    actionSheet.present();
  }

  deletMessage(subtitle){
    console.log("hello");
  }

}

is there any mistake which i did please let me know, thanks in advance

sandeep
  • 501
  • 4
  • 16
  • 2
    This question is being asked every other day. Use arrow functions: `handler: () => this.deletMessage("you just click on delete button")`. And while you're at it, rename it to `deleteMessage`. – JB Nizet Aug 13 '17 at 17:11
  • thankx a lot sir, i really did't get the answers of those question that are previously asked by another .thankx a lot, but i have a question which function is suitable in typescript ( => or function() ) .and what are the difference between both of these two type of function. – sandeep Aug 13 '17 at 17:24

0 Answers0