Angular4 Web Worker application not displaying

无人久伴 提交于 2019-12-04 17:52:16

I was also referencing the Angular with Web Workers: Step by Step post on Medium (as did the OP). One of the comments on that post mentioned including WORKER_UI_LOCATION_PROVIDERS and WORKER_APP_LOCATION_PROVIDERS into your application.

In your main.ts, add WORKER_UI_LOCATION_PROVIDERS as the second argument of bootstrapWorkerUi()

...
import {
  bootstrapWorkerUi,
  WORKER_UI_LOCATION_PROVIDERS
} from '@angular/platform-webworker'
...

bootstrapWorkerUi('webworker.bundle.js', WORKER_UI_LOCATION_PROVIDERS);

In your AppModule, add WORKER_APP_LOCATION_PROVIDERS. I also needed to provide a value for base href (which I've included below)

...
import {
  WorkerAppModule,
  WORKER_APP_LOCATION_PROVIDERS
} from '@angular/platform-webworker';
import { APP_BASE_HREF } from '@angular/common'
...

@NgModule({
  ...
  imports: [
    ...
    WorkerAppModule,
    ...
  ],
  ...
  providers: [
    ...
    {
      provide: APP_BASE_HREF,
      useValue: '/'
    },
    WORKER_APP_LOCATION_PROVIDERS
    ...
  ],
  ...
})

That should get you past your PlatformLocation provider problem, and maybe even your future base href problem.

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!