简体   繁体   English

单独的窗口/选项卡之间的Angular 2+交互

[英]Angular 2+ Interaction between separate windows/tabs

I've searched about this topic but couldn't find anything relevant. 我已经搜索了有关此主题的内容,但找不到任何相关内容。 I would like to know if, using Angular 2+ (optimally v5.4.2), something like this is possible. 我想知道,如果使用Angular 2+(最佳v5.4.2),是否可以实现这种效果。

Let me define a quick use case : 让我定义一个快速用例:

  • I have an app with multiple routes, 我有一个包含多条路线的应用,
  • open a browser on app/route1 (window1), 在app / route1(window1)上打开浏览器,
  • open a second browser window on app/route2 (window2) 在app / route2(window2)上打开第二个浏览器窗口
  • have a user input on window2 在window2上有用户输入
  • change data/ui on window1 according to the previous input. 根据先前的输入在window1上更改数据/用户界面。

Again, I don't even know if that is possible so even a simple "You can't" is ok with me. 再说一次,我什至不知道这是否可行,所以即使是一个简单的“你不能”也可以。

Thanks. 谢谢。

Since it's not tested, I am not sure if it's working but have you tried using localStorage to do this? 由于尚未测试,因此不确定其是否正常运行,但是您是否尝试过使用localStorage进行此操作? Otherwise, since a new window is always a new instance of the app, I don't think that anything directly in Angular would work (not sure though). 否则,由于新窗口始终是该应用程序的新实例,因此我认为直接在Angular中执行任何操作都不可行(尽管不确定)。

Otherwise, if you have a expressjs (or Node.js) server setup, you can store your data this way. 否则,如果您有expressjs(或Node.js)服务器设置,则可以这种方式存储数据。

There is several ways to achieve this. 有几种方法可以实现此目的。

If window2 input is updating data on a remote server, you could use websockets or any other real time technology to notify window1 that your data has changed. 如果window2输入正在更新远程服务器上的数据,则可以使用websockets或任何其他实时技术来通知window1您的数据已更改。

An other alternative would be to use localStorage . 另一种选择是使用localStorage You should check out this stackoverflow post for more informations on that. 您应该查看此stackoverflow帖子以获取有关此信息的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM