我正在努力在我关注的应用程序的所有打开的选项卡之间进行通信
Communication between tabs or windows
但我没有收到事件
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'selector',
template: require('./app.component.html'),
styles: [require('./app.component.css')]
})
export class AppComponent {
constructor(){
// listen event
window.addEventListener('storage', this.message_receive);
// to trigger dummy events
setInterval(() => {
this.message_broadcast({a: 'rhushi'});
}, 1000);
}
public message_broadcast(message) {
localStorage.setItem('message', JSON.stringify(message));
}
public message_receive(ev) {
if (ev.key === 'message') {
let message = JSON.parse(ev.newValue);
}
}
}
如果我在这里出错,请纠正我