Angular广播/消息通知的接收与发送
一、在接收页:
添加引用: private eventManager: JhiEventManager;
备注:记得在页面开始事件中添加接收通知的方法
发送通知的方法:
下面是自己写的办法:
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("收到了,我立马刷新列表");
}
});
}
}
最新文章
- Windows 安装JRuby 生成 war 到 tomcat 运行
- flex 弹性布局
- target=";_blank";
- Minimum configuration for openldap to proxy multiple AD into a single search base
- 将Discuz.net 集成到asp.net
- css渐变
- zookeeper笔记
- Dynamic Binding &; Static Binding
- Java基础学习笔记2-循环
- 什么是TimeTunnel
- 从零開始学android&;lt;SeekBar滑动组件.二十二.&;gt;
- UNIX基础知识--<;<;UNIX 环境编程>;>;读书笔记
- hibernate ——联合主键
- RMQ问题(线段树算法,ST算法优化)
- (知识点)JS获取网页高度
- TP5多模块开发
- 初识STL vector
- thinkphp通用控制器
- 160. Intersection of Two Linked Lists(剑指Offer-两个链表的第一个公共结点)
- nginx安装最简单教程
热门文章
- IOS 字典模型互转框架 MJExtension
- 【Java 安全技术探索之路系列:J2SE安全架构】之二:安全管理器
- jupyter环境的安装
- Linux __setup解析【转】
- inexact rename detection was skipped due to too many files
- BZOJ_3105_[cqoi2013]新Nim游戏_线性基+博弈论
- STM32F4 DMA2D_M2M_PFC
- 切换或者用户登录时 出现 显示 -bash-4.2$ 问题 的解决
- bzoj 1025: [SCOI2009]游戏【数学+dp】
- bzoj 4071: [Apio2015]巴邻旁之桥【splay】