在AlertController

时间:2016-09-06 16:33:57

标签: angular typescript ionic2

我正在尝试使用来自离子的警报控制器,但是当将方法传递给处理程序选项时,我在实例上声明的处理程序方法中使用的任何方法在单击时都显示为未找到选择按钮。我有两个按钮,一个显示cancel,另一个显示delete。单击d delete按钮时出现错误。我有以下内容:

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

}

我收到错误消息,指出找不到this.createForm

错误

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]

0 个答案:

没有答案