【angular5项目积累总结】消息订阅服务
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项目积累总结】消息订阅服务的更多相关文章
- 【angular5项目积累总结】http请求服务封装
http.provider.ts import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/co ...
- 【angular5项目积累总结】遇到的一些问题以及解决办法
1.项目中字符串特别是\r\n,替换成br之后,在页面换行无法生效? 答:绑定元素 innerHTML. <div class="panel-body" [innerHTML ...
- 【angular5项目积累总结】侧栏菜单 navmenu
View Code import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/co ...
- 【angular5项目积累总结】avatar组件
View Code import { Component, HostListener, ElementRef } from '@angular/core'; import { Adal4Service ...
- 【angular5项目积累总结】breadcrumb面包屑组件
view code <div class="fxs-breadcrumb-wrapper" aria-label="Navigation history" ...
- 【angular5项目积累总结】结合adal4实现http拦截器(token)
import { Injectable } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRe ...
- 【angular5项目积累总结】文件上传
<div class="form-group row"> <label class="col-sm-2 col-form-label"> ...
- 【angular5项目积累总结】文件下载
download() { const token = localStorage.getItem('token'); let headers: HttpHeaders = new HttpHeaders ...
- 【angular5项目积累总结】自定义管道 OrderBy
import { Injectable, Pipe } from '@angular/core'; @Pipe({ name: 'orderBy' }) @Injectable() export cl ...
随机推荐
- 开源应用框架BitAdminCore:更新日志20180605
索引 NET Core应用框架之BitAdminCore框架应用篇系列 框架演示:http://bit.bitdao.cn 框架源码:https://github.com/chenyinxin/coo ...
- 数据库表结构文档查看器 基于netcore
前言 日常开发业务代码,新接手一块不熟悉的业务时需要频繁的查看对应业务的数据库表设计文档.相比于直接翻看业务代码,有必要提供一个数据库表结构文档查看器来解决这些繁琐的问题. CML.SqlDoc CM ...
- TOJ1398正方形的编成 或者 POJ2362
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...
- 基于JSP的在线考试系统-JavaWeb项目-有源码
开发工具:Myeclipse/Eclipse + MySQL + Tomcat 系统简介: 网络考试系统主要用于实现高校在线考试,基本功能包括:自动组卷.试卷发布.试卷批阅.试卷成绩统计等.本系统结构 ...
- Termux中安装gcc-7/gfortran-7实操过程,安装成功可以编译Fortran,c/c++
最近计算材料学的老师需要我们运行Fortran,又不想带电脑去教室.所以想起Termux了,于是就试试看这个宝贝能不能帮我的忙, 但是经过测试以后发现,clang只能编译c/c++那一类语言,不能编译 ...
- 利用C# CefSharp Python采集某网站简历并自动发送邀请短信
以往爬虫没怎么研究过,最近有个需求,要从某网站采集敏感信息,稍稍考虑了一下,决定利用C# Winform和Python一起来解决这个事件. 整个解决方案不复杂:C#编写WinForm窗体,进行数据分析 ...
- python 去除字符串的首末两端的空白字符
my_str = " adsffff adsfsad " my_str.strip() 使用strip()默认将 str 两端的空白字符去除掉 同时还有rstrip() 和 lst ...
- django 视图 使用orm values_list()方法获取 指定的 多个字段的数据
from .models import UserInfodata_set = UserInfo.objects.all().values_list("user_name", &qu ...
- combining-filters
The previous two examples showed a single filter in use. In practice, you will probably need to filt ...
- GraphQL 如何取代 Redux
简评:使用 GraphQL 可以大大简化客户端状态管理部分的代码. ⚛️切换到React 故事背景:在 2016 年,Pathwright 的前端团队就开始将客户端的代码从 Backbone & ...