Skip to content

Service worker cannot be enabled by function factory with AOT #22796

@Serginho

Description

@Serginho

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ X ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

ServiceWorkerModule.register('/ngsw-worker.js', {enabled: [boolean]});

Expected behavior

ServiceWorkerModule.register('/ngsw-worker.js', {enabled: enableServiceWorker()});

or

{provide: RegistrationOptions, useFactory: () => {enabled: enableServiceWorker()}}

This way is not possible because RegistrationOptions is not exported.

What is the motivation / use case for changing the behavior?

Export RegistrationOptions provider in order to change the implementation.

The environment variable of my app is splitted in serveral files and joined with a merge function. So AOT fails registering service worker. The solution is enable it by Dependency injection but the provider is not public.
export const environment = merge([{}, ENVIRONMENT_DEV, ENVIRONMENT_GLOBAL, { ... }]);

Environment


Angular version: 5.2.9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions