Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(ngrx/data): correct AppEntityServices example in ngrx data doc page #2413

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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