Javascript 同一组件的两个窗口之间的角度通信

Javascript 同一组件的两个窗口之间的角度通信,javascript,angular,window.open,postmessage,window.opener,Javascript,Angular,Window.open,Postmessage,Window.opener,我正在尝试实现两个窗口之间的通信 我使用window.open()打开组件新2窗口 问题在于,两个窗口中的同一组件2个不同实例无法在这两个窗口之间通信 你能帮忙吗? 您可以尝试BroadsastChannel API: 这就是它所针对的场景 这相当简单。摘自文件: // Connection to a broadcast channel var bc = new BroadcastChannel('test_channel'); // Example of sending of a very

我正在尝试实现两个窗口之间的通信

我使用
window.open()
打开组件新2窗口

问题在于,两个窗口中的同一组件2个不同实例无法在这两个窗口之间通信

你能帮忙吗?

您可以尝试BroadsastChannel API:

这就是它所针对的场景

这相当简单。摘自文件:

// Connection to a broadcast channel
var bc = new BroadcastChannel('test_channel');

// Example of sending of a very simple message
bc.postMessage('This is a test message.');

// Example of a simple event handler that only
// logs the event to the console
bc.onmessage = function (ev) { console.log(ev); }

// Disconnect the channel
bc.close()

参考这个,希望这有帮助!您不可能没有得到事件,因为您可以使用套接字进行相同的操作,并且您还需要更改后端的代码