Angular 2调用函数从一个组件到另一个组件

如何使用Angular 2将函数从一个组件调用到另一个组件 . 我在父组件中有一个名为' deleteAccount() '的函数 . 但我想从子组件中调用它 .

我尝试使用@viewChild,但我收到错误说,无法读取未定义的属性'deleteAccount'

我有一个模板,

<ion-item>
        <ion-grid>  
          <ion-row>
            <ion-col width-50>
              <strong>BankName:</strong>
            </ion-col>
            <ion-col width-50>
              syndicate
            </ion-col>
          </ion-row>
        </ion-grid>
        <button ion-button item-right (click)="presentPopover($event, acclist)">
          <ion-icon name="more"></ion-icon>
        </button>
      </ion-item>

而ts文件,

import { Component, Input, ViewChild } from '@angular/core';
     import { NavController, Events, PopoverController, ViewController, NavParams, AlertController } from 'ionic-angular';
     @Component({
        templateUrl: 'build/pages/addaccount/accountlistview.html'         
     })
     export class accountListView {
         constructor(
          private popoverCtrl: PopoverController,
          public viewCtrl: ViewController,
          public navParams: NavParams
          ) {

          }

          presentPopover(event, item) {
           let popover = this.popoverCtrl.create(PopoverPage, {"selectedItem": item});
           popover.present({
           ev: event
        });
      } 

      deleteAccount(item){

      }

      }

    @Component({
     template: `
       <ion-list>
         <button ion-item (click)="accountRemoveConfirm()">Delete</button>
       </ion-list>
      `
})
class PopoverPage {
  selectedAccObj = {};
  @ViewChild(accountListView) childcmp:accountListView;
  constructor(
    public viewCtrl: ViewController,
    public navParams: NavParams,
    public alertCtrl: AlertController
    ){
     this.selectedAccObj = navParams.get('selectedItem');
   }

  accountRemoveConfirm() {
    this.childcmp.deleteAccount(this.selectedAccObj);
    this.viewCtrl.dismiss();  
   }
}

回答(0)