Ngrx/data, how to add a plural names map in a lazy loaded module?

436 Views Asked by At

From the docs, I've tried to add the following provider in my lazy loaded Angular module...

{ provide: PLURAL_NAMES_TOKEN, multi: true, useValue: morePluralNames }

...but that is not working. A similar mechanism is described in the documentation as follows...

{ provide: ENTITY_METADATA_TOKEN, multi: true, useValue: someEntityMetadata }

This technique won't work for a lazy-loaded module. The ENTITY_METADATA_TOKEN provider was already set and consumed by the time the lazy-loaded module arrives.

The module should inject the EntityDefinitionService instead and register metadata directly with one of the registration methods.

class LazyModule {
  constructor(eds: EntityDefinitionService) {
    eds.registerMetadataMap(this.lazyMetadataMap);
  }
  ...
}

Does that mean I have to use the EntityDefinitionService in order to get my plural names recognized in my lazy loaded module? If so, how do I do that? I haven't been able to figure that out. If not, any ideas on what I'm doing wrong?

I can supply more code if needed, but I mainly wanted to know if it should be working or if I need to do something different for plural names maps in lazy loaded modules (and exactly what that "something different" is).

1

There are 1 best solutions below

0
On

By the document, you can register your own httpUrlGenerator in your lazy loading module, it works for me.

export class LazyModule {
    constructor(eds: EntityDefinitionService, hug: HttpUrlGenerator  ) {
        eds.registerMetadataMap(entityConfig.yourEntitiyMetaData);
        hug.registerHttpResourceUrls({
            input: {
                entityResourceUrl: 'xxx/input/',            
                collectionResourceUrl: 'xxx/inputs/'
            }
        });
    }

 }