zoukankan      html  css  js  c++  java
  • 【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');

  • 相关阅读:
    Java集合之LinkedHashMap
    ConcurrentHashMap原理分析
    Java集合之HashMap
    JAVA集合之ArrayList
    Python内建函数
    Vscode 安装Java Spring项目
    音频质量评估-2
    音频质量评估-1
    Python list 实现
    怎么测试大数据
  • 原文地址:https://www.cnblogs.com/sybboy/p/8386285.html
Copyright © 2011-2022 走看看