ionic4 返回上一页并刷新

场景再现:
1.任务类表页面(父页面)
2.任务详情页面(子页面)
问题: 在子页面对数据进行了修改,然后返回到 父页面, 数据没有实时更新!
1.新建立一个服务services

ionic g service services/event

2.安装配置EventEmitter:

npm install--save eventemitter3

3.定义公共的服务配置

import { Injectable } from '@angular/core';
import {EventEmitter} from 'eventemitter3';
@Injectable({
  providedIn: 'root'
})
export class EventService {
  public event: any;
  constructor() { 
    this.event=new EventEmitter();  //这个实例就会被多个组件共享,来实现不同页面的数据通信
  }
}

4.子页面消失的时候发送广播

  1. 先引入 : EventService
import{EventService}from'../services/event.service';
  1. 声明:
 public eventService: EventService
  1. 监听:
    //通知printscreenstu相册的页面更新信息 ,也就是上面所说的页面B
    this.eventService.event.emit('useraction');

5.父页面监听事件广播

  1. 先引入 : EventService
import{EventService}from'../services/event.service';
  1. 声明:
 public eventService: EventService
  1. 监听事件广播,通知页面a更新数据
    this.eventService.event.on('useraction', () => {
      this.GetStuAllFirstPicture();
    })

原链接:https://blog.csdn.net/jerry11112/article/details/91346934

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值