Skip to content

Commit

Permalink
fix(data): correct AppEntityServices example in ngrx data doc page (#…
Browse files Browse the repository at this point in the history
…2413)

closes #2280
  • Loading branch information
wardbell authored Feb 26, 2020
1 parent c9ebb06 commit 711ba0e
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions projects/ngrx.io/content/guide/data/entity-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,43 +135,38 @@ The following `AppEntityServices` demonstrates.

<code-example header="app-entity-services.ts">
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import {
EntityCache,
EntityCollectionServiceFactory,
EntityServicesBase
} from '@ngrx/data';
import { EntityServicesBase, EntityServicesElements } from '@ngrx/data';

import { SideKick } from '../../model';
import { HeroService, VillainService } from '../../services';

@Injectable()
export class AppEntityServices extends EntityServicesBase {
constructor(
public readonly store: Store&lt;EntityCache&gt;,
public readonly entityCollectionServiceFactory: EntityCollectionServiceFactory,
elements: EntityServicesElements,

// Inject custom services, register them with the EntityServices, and expose in API.
public readonly heroesService: HeroesService,
public readonly villainsService: VillainsService
readonly heroesService: HeroesService,
readonly villainsService: VillainsService
) {
super(store, entityCollectionServiceFactory);
super(elements);
this.registerEntityCollectionServices([heroesService, villainsService]);
}

// ... Additional convenience members

/** get the (default) SideKicks service */
get sideKicksService() {
return this.getEntityCollectionService&lt;SideKick&gt;('SideKick');
}
}
</code-example>

`AppEntityServices` injects the two custom collection services, `HeroesService` and `VillainsService`,
which it also exposes directly as convenience properties.
`AppEntityService` first injects the `EntityServicesElements` helper which it passes straight through to the base class constructor.
The "elements" enclose the ingredients that the base class needs to make and manage the entities you described in metadata.

Then it injects your two custom collection services, `HeroesService` and `VillainsService`,
and exposes them directly to consumers as convenience properties for accessing those services.

There is no custom collections service for the `SideKick`.
In this example, we don't need a custom collection service for the `SideKick` entity.
The default service will do.

Nonetheless, we add a `sideKicksService` property that gets or creates a default service for `SideKick`.
Expand Down

0 comments on commit 711ba0e

Please sign in to comment.