ngx-tonidigital-configuration
v15.2.4
Published
**Package Name:** ngx-tonidigital-configuration
Downloads
1
Readme
Configuration Service
Package Name: ngx-tonidigital-configuration
How to use
This service should not be imported and used directly across the app. You need to create a service in your app and extend this class. Then import and use your own service across your application.
Because this package is type agnostic. Every app’s configuration would be different so can include different fields.
Your local service will include type definitions of your app’s configuration. Also you can define your own methods in your service.
Create your own service, import and extend this package’s base class:
import { ConfigurationServiceBase } from "ngx-tonidigital-configuration"; interface IStaticConfig { staticApiURL: string; gatewayApi: string; } interface IConfig { authApi: string; commonApi: string; newAuthApi: string; ... // Define your configuration file fields } @Injectable({ providedIn: "root" }) export class ConfigurationService extends ConfigurationServiceAbstract<IConfig, IStaticConfig> { constructor(protected httpClient: HttpClient, protected storageService: StorageService) { super(httpClient, storageService); } public yourCustomMethod(): Promise<string> { return this.config.companyName.toUpperString() ; } }
Import base class from package in your app.module and add below provider entry. This will provide your own ConfigurationService to the other ngx-tonidigital packages that you imported in your app. This ensures that ConfigurationService will work as singleton service while allowing you to extend it. One instance will be shared among your app and other packages.
import { ConfigurationServiceBase } from "ngx-tonidigital-configuration"; { providers: [ { provide: ConfigurationServiceBase, useExisting: ConfigurationService }, ... ] }