code

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class CommonService {
private notify = new Subject<any>();
/**
* Observable string streams
*/
notifyObservable$ = this.notify.asObservable(); constructor() { } public notifyOther(data: any) {
if (data) {
this.notify.next(data);
}
}
}

项目示例

表单提交后更新其他组件数据列表

定义:

  constructor(
private router: Router,
private actRouter: ActivatedRoute,
private appStoreService: AppStoreService,
private comService: CommonService) {
this.subscribeUpdate(comService);
} subscribeUpdate(comService: CommonService) {
this.comService.notifyObservable$.subscribe(data => {
if (data == 'refreshWebApp') {
this.loadWebApp();
}
}, error => {
console.log(`subscribe error:${error}`)
})
}

调用:

this.comService.notifyOther('refreshWebApp');

【angular5项目积累总结】消息订阅服务的更多相关文章

  1. 【angular5项目积累总结】http请求服务封装

    http.provider.ts import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/co ...

  2. 【angular5项目积累总结】遇到的一些问题以及解决办法

    1.项目中字符串特别是\r\n,替换成br之后,在页面换行无法生效? 答:绑定元素 innerHTML. <div class="panel-body" [innerHTML ...

  3. 【angular5项目积累总结】侧栏菜单 navmenu

    View Code import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/co ...

  4. 【angular5项目积累总结】avatar组件

    View Code import { Component, HostListener, ElementRef } from '@angular/core'; import { Adal4Service ...

  5. 【angular5项目积累总结】breadcrumb面包屑组件

    view code <div class="fxs-breadcrumb-wrapper" aria-label="Navigation history" ...

  6. 【angular5项目积累总结】结合adal4实现http拦截器(token)

    import { Injectable } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRe ...

  7. 【angular5项目积累总结】文件上传

    <div class="form-group row"> <label class="col-sm-2 col-form-label"> ...

  8. 【angular5项目积累总结】文件下载

    download() { const token = localStorage.getItem('token'); let headers: HttpHeaders = new HttpHeaders ...

  9. 【angular5项目积累总结】自定义管道 OrderBy

    import { Injectable, Pipe } from '@angular/core'; @Pipe({ name: 'orderBy' }) @Injectable() export cl ...

随机推荐

  1. 一键部署react到nginx上

    仅用于记录自己的程序部署 cd /home/web; rm -rf JulyNovelReact; mkdir JulyNovelReact; cd JulyNovelReact; rz; tar - ...

  2. sqlcmd 执行SQL语句或没有足够的内存来执行脚本

    win+r命令提示框里面输入cmd sqlcmd -S . -U username -P password -d database -i url -S 数据库地址 -U 登录名称 -P 密码 -d 数 ...

  3. 快速排序 JAVA实现

    快速排序 每次排序的时候设置一个基准点,将小于等于基准点的数全部放到基准点的左边,将大于等于基准点的数全部放到基准点的右边.快速排序是不稳定的,时间复杂度(平均):nlogn public class ...

  4. 《快学Scala》第三章 数组相关操作

  5. [JS] 屏蔽右键

    if (window.Event) document.captureEvents(Event.MOUSEUP); function nocontextmenu() { event.cancelBubb ...

  6. su: Authentication failure 的解决方案

    原因是:ubuntu默认不允许使用root登录,因此初始root账户是不能使用的,需要在普通账户下利用sudo权限修改root密码. 解决方案很简单:设置一个root密码就行了.注意是sudo 而不是 ...

  7. 使HTML页面上获取到的文本保留空格和换行符等格式

    <pre> 元素可定义预格式化的文本.被包围在 pre 元素中的文本通常会保留空格和换行符.而文本也会呈现为等宽字体.   <pre>的内容自动换行的问题(兼容多个浏览器): ...

  8. 人工鱼群算法超详细解析附带JAVA代码

    01 前言 本着学习的心态,还是想把这个算法写一写,给大家科普一下的吧. 02 人工鱼群算法 2.1 定义 人工鱼群算法为山东大学副教授李晓磊2002年从鱼找寻食物的现象中表现的种种移动寻觅特点中得到 ...

  9. java连接SqlServer2012

    要用java连接数据库  首先是要通过JDBC驱动 要先去下载一个sqljdbc4.jar,我这里放百度云盘了, 下载地址:链接:http://pan.baidu.com/s/1slJl89B 密码: ...

  10. 说说MySQL权限

    前言 今天继续MySQL系列文章,讲讲MySQL权限相关的内容.我们都知道,在写系统的时候,都会有权限相关的服务,以达到权限控制的目的.以最简单的权限菜单为例: 管理员拥有最大权限,可以查看系统下所有 ...