Angular with Web Workers: Step by step
Enrique oriol

Hi Enrique oriol,

Thanks for the article. Really helped me to get started with platform-webworker. I’ve still got a ways to go, but I’ve found a few things that might interest people.

First: The No provider for PlatformLocation issue everyone keeps mentioning — I’ve found the solution. There’s a set of providers for the UI and App side found in the platform-webworker code which handle this: WORKER_UI_LOCATION_PROVIDERS and WORKER_APP_LOCATION_PROVIDERS.
The first can be passed as a second param to bootstrapWorkerUi(), and the second can be added to your AppModule.
Make sure both are getting loaded (as in, one on the UI and one in the App) — I was tearing my hair out for a few hours because I only included WORKER_APP_LOCATION_PROVIDERS, and it was sitting there waiting to get a message from a service provided through WORKER_UI_LOCATION_PROVIDERS.
I’m not sure why they’re not automatically included. Guessing it’s just an oversight — platform-webworker is still considered “experimental” after all.

I also recommend taking a look at how platform-webworker handles calling the DOM from the WebWorker via the ServiceMessageBrokerFactory, and how any services provided to the Worker UI will have their start() method (if they have any) called automatically, so it can setup message brokers. It’s kind of a ngOnInit() for Worker UI services.
For example — Take a look at the MessageBasedPlatformLocation service:
Compare it to it’s matching WebWorkerPlatformLocation service:

Jason Stone