Taxonomy Service
This provides a service for other components to use to retrieve taxonomy information.
Requirements
The Taxonomy Service interface:
export interface TaxonomyOption {
name: string; // The name of the taxonomy option
fullName: string; // The full name of the taxonomy option, including parent taxonomies
id: string; // The id that represents this taxonomy option
}
export interface TaxonomyServiceInterface {
getTaxonomyIds(): Observable<TaxonomyOption[]>;
}
To implement the interface make a new service that implements the interface:
…
import {TaxonomyServiceInterface} from '@vendasta/taxonomy-service';
@Injectable()
export class TaxonomyService implements TaxonomyServiceInterface {
…
getTaxonomyIds(): Observable<string[]> {
// Implement how the project determines taxonomy ids
}
}
Next you will need to provide your service as that interface (generally in app.module.ts
)
import { TaxonomyService } from './taxonomy.service';
import { TaxonomyServiceInterfaceToken } from '@vendasta/taxonomy-service';
…
@NgModule({
…
providers: [
TaxonomyService, {provide: TaxonomyServiceInterfaceToken, useExisting: TaxonomyService}
],
})
- Note: To be able to inject an interface, you will have to provide the InjectionToken and not the interface itself (
TaxonomyServiceInterfaceToken
vsTaxonomyServiceInterface
).