이 페이로드 객체를 각도 4 컴포넌트에 전달하는 방법은 무엇입니까? 나는 PostMessage를 읽어하지만 그것은 나를 위해 일을 어쩌려 구`t :(누군가가 괜찮 작동하는 방법을 설명 할 수postMessage 객체 from 서비스 작업자
이서비스 노동자 :
이messaging.setBackgroundMessageHandler((payload) => {
const notificationOptions = {
"body": data.body,
"icon": "icon.png",
"click_action": click_action
};
postMessage({'test'});
return self.registration.showNotification(notificationTitle, notificationOptions);
});
구성 요소 :
export class AppComponent implements OnInit {
constructor() {}
ngOnInit() {
navigator.serviceWorker.addEventListener('message', function(event) {
console.log("Got reply from service worker: " + event.data);
});
self.addEventListener('message', event => {
console.log('MESSAGE: ',event.data);
});
}
}