Home:ALL Converter>Ionic 2 instance Method not found in AlertController

Ionic 2 instance Method not found in AlertController

Ask Time:2016-09-07T00:33:57         Author:Abdullah Rasheed

Json Formatter

I'm attempting to use Alert Controller from ionic, but when passing a method to the handler option, any methods that I use inside of the handler method that I've declared on the instance are being shown as not found when clicking the select button. I have two buttons, one says cancel and the other is for delete. When clicking the ddelete button I get the error. I have the following:

CODE

import { Component, ViewChild, OnInit } from '@angular/core';
import { FormBuilder, ControlGroup, Validators } from '@angular/common';
import { AlertController,LoadingController, NavController, ModalController, Slides, ViewController } from 'ionic-angular';

import { ShareUsageService } from './share.service';

@Component({
    selector:'brt-share',
    templateUrl: 'build/share/share.component.html'
})
export class ShareUsageComponent implements OnInit{
    //public properties
    emailForm: ControlGroup;
    submitAttempt: boolean = false;
    friends: string[] = [];

    constructor(
        public alertController: AlertController,
        public formBuilder: FormBuilder, 
        public shareService: ShareUsageService){
        this.createForm();
    }

    ngOnInit(){
        this.shareService.getFriends()
            .then(data => {this.friends = data;});

    }
    // public methods

    /**
     * @name deleteFriend
     * @description
     * Dismisses the modal to show the request view.
     */
    deleteFriend(){
        this.createForm();
        this.shareService.deleteFriend()
            .then(data => this.friends = data);
    }

    showDeleteConfirm(friendEmail:string) {
    let confirm = this.alertController.create({
      title: 'Delete this Friend?',
      message: 'Are you sure you to delete ' + friendEmail + '. This friend will no longer have access to your data.' ,
      buttons: [
        {
          text: 'Cancel',
          handler: () => {
            console.log('Cancel clicked');
          }
        },
        {
          text: 'Delete',
          handler: this.deleteFriend 
        }
      ]
    });
    confirm.present();
  }

    createForm(){
        this.emailForm = this.formBuilder.group({
            email:['', Validators.compose([Validators.required])]
        });
    }

}

I get an error saying that this.createForm is not found.

ERROR

zone.js:260 Uncaught EXCEPTION: Error in ./AlertCmp class AlertCmp - inline template:42:68
ORIGINAL EXCEPTION: TypeError: this.createForm is not a function
ORIGINAL STACKTRACE:
TypeError: this.createForm is not a function
    at Object.ShareUsageComponent.deleteFriend [as handler] (http://10.229.100.115:8100/build/js/app.bundle.js:890:14)
    at AlertCmp.btnClick (http://10.229.100.115:8100/build/js/app.bundle.js:51780:24)
    at DebugAppView._View_AlertCmp10._handle_click_0_0 (AlertCmp.template.js:1130:35)
    at http://10.229.100.115:8100/build/js/app.bundle.js:32781:24
    at http://10.229.100.115:8100/build/js/app.bundle.js:46228:36
    at http://10.229.100.115:8100/build/js/app.bundle.js:46314:111
    at ZoneDelegate.invoke (http://10.229.100.115:8100/build/js/zone.js:323:29)
    at Object.onInvoke (http://10.229.100.115:8100/build/js/app.bundle.js:38148:41)
    at ZoneDelegate.invoke (http://10.229.100.115:8100/build/js/zone.js:322:35)
    at Zone.runGuarded (http://10.229.100.115:8100/build/js/zone.js:230:48)
ERROR CONTEXT:
[object Object]

Author:Abdullah Rasheed,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39353863/ionic-2-instance-method-not-found-in-alertcontroller
yy