ionic4|5 使用PopoverController 控件

效果图

Step 1  TS建立弹出界面组件并引入PopoverController组件

import { Component, OnInit } from '@angular/core';
import { PopoverController} from '@ionic/angular';

@Component({
  selector: 'app-poppickstyle',
  templateUrl: './poppickstyle.component.html',
  styleUrls: ['./poppickstyle.component.scss'],
})
export class PoppickstyleComponent implements OnInit {
  public data: any;

  constructor(
    private popCtl: PopoverController,
  ) { }

  ngOnInit() {}


  onPick(pickId) {
    console.log('pick id===>', pickId);
    this.popCtl.dismiss(pickId);
  }
}

Step 2 HTML 加入要显示的内容

<ion-list class="lHead" lines="false" inset="true"> 
  <div >Report display style</div>
  <ion-item (click)="onPick(1)">
    <ion-icon name="pie-chart-outline"></ion-icon>
    <ion-label>Pie</ion-label>
  </ion-item>
  <ion-item (click)="onPick(2)">
    <ion-icon name="pulse-outline"></ion-icon>
    <ion-label>Line</ion-label>
  </ion-item>
  <ion-item (click)="onPick(3)">
    <ion-icon name="bar-chart-outline"></ion-icon>
    <ion-label>Bar</ion-label>
  </ion-item>
</ion-list> 

Step 3 要使用的地方加入代码

import { Component, OnInit } from '@angular/core';
import { PopoverController } from '@ionic/angular';
import { PoppickstyleComponent } from '../../components/poppickstyle/poppickstyle.component';


@Component({
  selector: 'app-report',
  templateUrl: 'report.page.html',
  styleUrls: ['report.page.scss']
})
export class ReportPage implements OnInit {

  constructor(
    private popoverCtl: PopoverController,
  ) {}

  ngOnInit(): void {
  }

  async presentPopover(ev: any) {
    const popover = await this.popoverCtl.create({
      component: PoppickstyleComponent,
      event: ev,
      translucent: true,
    });

    //这里是传过去的值
    popover.onDidDismiss().then(v => {
      console.log('close pop',  v);
    });
    return await popover.present();
  }

}

参考文献 https://www.freakyjolly.com/ionic-modal-popovers-pass-receive-data/

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值