如何在弹出窗口中使用相同的服务实例?

发布于 2025-01-18 05:42:46 字数 430 浏览 2 评论 0原文

我正在尝试使用通信服务在不同角度组件之间发送一些数据。但是当子组件在弹出窗口中打开时,我遇到了一个问题。因为它本身就是一个单独的角度应用程序。因此它采用了不同的服务实例,因此我无法发送数据。

这是我的通讯服务。

import { Injectable } from "@angular/core";
import { Subject } from "rxjs";

@Injectable()
export class CommunicatingService {
  private subject = new Subject<any>();
  sub = this.subject.asObservable()
  constructor() {}

  nextSub(data: any) {
    this.subject.next(data)
  }
}

I am trying to use a communication service to send some data between different angular components. But I am facing an issue when the child component is opened inside a pop-up window. Since it is a separate angular app itself. So it's taking a different instance of the service and thus I am unable to send data.

This is my communication Service.

import { Injectable } from "@angular/core";
import { Subject } from "rxjs";

@Injectable()
export class CommunicatingService {
  private subject = new Subject<any>();
  sub = this.subject.asObservable()
  constructor() {}

  nextSub(data: any) {
    this.subject.next(data)
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文