this.function不是函数:typescript

时间:2017-08-13 17:07:26

标签: typescript ionic2

我是离子的新手,我在处理程序中调用另一个函数的函数时遇到错误,我得到错误this.deletMessage is not a function这里是代码:

    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");
  }

}

我有什么错误请事先知道,谢谢

0 个答案:

没有答案