一、在接收页:
添加引用: private eventManager: JhiEventManager;

接收通知的方法:

// 接收通知(新建、编辑、删除页发送过来的通知) // upmsMenuListModification 接收的内容(随意)
registerChangeEvent() {
this.eventSubscriber = this.eventManager.subscribe('upmsMenuListModification', response => this.loadAll());
}

备注:记得在页面开始事件中添加接收通知的方法

二、在发送通知页:
添加引用:private eventManager: JhiEventManager
发送通知的方法:
// 发送通知 upmsMenuListModification发送的内容(随意)
private onSaveSuccess() {
this.eventManager.broadcast({ name: 'upmsMenuListModification' });
}
以上是angular自带的组件
下面是自己写的办法:
第一步:先创建一个service

import {Injectable, EventEmitter, OnInit} from "@angular/core";
@Injectable()
export class EmitService implements OnInit {
public eventEmit: any;

constructor() {
// 定义发射事件
this.eventEmit = new EventEmitter();
}

ngOnInit() {

}
}

备注:记得在Module中添加这个service的引用

第二步:

发送通知页:

import {Component} from '@angular/core';
import {EmitService} from "./emit.service"
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(public emitService: EmitService) {

}

emitFun() {
// 如果组件中,修改了某些数据,需要刷新用用户列表,用户列表在其他组件中,那么就可以发射一个字符串过去,那边接收到这个字符串比对一下,刷新列表。
this.emitService.eventEmit.emit("userList");
}
}

接收通知页:

import {Component, OnInit} from "@angular/core";
import {EmitService} from "./emit.service"
@Component({
selector: "event-emit",
templateUrl: "./emit.component.html"
})
export class EmitComonent implements OnInit {
constructor(public emitService: EmitService) {

}

ngOnInit() {
// 接收发射过来的数据
this.emitService.eventEmit.subscribe((value: any) => {
if(value == "userList") {
// 这里就可以调取接口,刷新userList列表数据
alert("收到了,我立马刷新列表");
}
});
}

}

 
 

最新文章

  1. Windows 安装JRuby 生成 war 到 tomcat 运行
  2. flex 弹性布局
  3. target="_blank"
  4. Minimum configuration for openldap to proxy multiple AD into a single search base
  5. 将Discuz.net 集成到asp.net
  6. css渐变
  7. zookeeper笔记
  8. Dynamic Binding & Static Binding
  9. Java基础学习笔记2-循环
  10. 什么是TimeTunnel
  11. 从零開始学android<SeekBar滑动组件.二十二.>
  12. UNIX基础知识--<<UNIX 环境编程>>读书笔记
  13. hibernate ——联合主键
  14. RMQ问题(线段树算法,ST算法优化)
  15. (知识点)JS获取网页高度
  16. TP5多模块开发
  17. 初识STL vector
  18. thinkphp通用控制器
  19. 160. Intersection of Two Linked Lists(剑指Offer-两个链表的第一个公共结点)
  20. nginx安装最简单教程

热门文章

  1. IOS 字典模型互转框架 MJExtension
  2. 【Java 安全技术探索之路系列:J2SE安全架构】之二:安全管理器
  3. jupyter环境的安装
  4. Linux __setup解析【转】
  5. inexact rename detection was skipped due to too many files
  6. BZOJ_3105_[cqoi2013]新Nim游戏_线性基+博弈论
  7. STM32F4 DMA2D_M2M_PFC
  8. 切换或者用户登录时 出现 显示 -bash-4.2$ 问题 的解决
  9. bzoj 1025: [SCOI2009]游戏【数学+dp】
  10. bzoj 4071: [Apio2015]巴邻旁之桥【splay】