Angular Environment Loader

Loads the environment properties from the provided asynchronous sources.

DefaultEnvironmentLoader

The default environment loader implementation to load the properties to the environment.

This loader is provided by defaut when running EnvironmentModule.forRoot(), but can be provided manually.

import { Provider } from '@angular/core';
import { EnvironmentLoader } from '@kuoki/environment';
import { DefaultEnvironmentLoader } from '@kuoki/environment-angular';

export const ENVIRONMENT_LOADER_PROVIDER: Provider = {
provide: EnvironmentLoader,
useClass: DefaultEnvironmentLoader
};

Unless ENVIRONMENT_SOURCES is provided, the initial sources value is null. To know more about the environment sources and its factory read the source tokens documentation or the sources documentation.

Use cases

Below are examples of the expected behavior and some implementation examples. To learn more about environment loader and how to create them you can read the documentation.

Table of Contents
  1. Create a custom loader

Create a custom loader

To create a custom environment loader that uses ENVIRONMENT_SOURCES_FACTORY simply complete the next class.

import { Inject, Injectable, Optional } from '@angular/core';
import { EnvironmentService, EnvironmentSource } from '@kuoki/environment';
import { DefaultEnvironmentLoader, ENVIRONMENT_SOURCES_FACTORY } from '@kuoki/environment-angular';

@Injectable()
export class CustomEnvironmentLoader extends DefaultEnvironmentLoader {
constructor(
protected override readonly service: EnvironmentService,

@Optional()
@Inject(ENVIRONMENT_SOURCES_FACTORY)
protected override readonly sources?: EnvironmentSource | EnvironmentSource[] | null
) {
super(service, sources);
}
}

Once implemented must be provided:

  1. Using the EnvironmentModule.forRoot().
import { EnvironmentModule } from '@kuoki/environment-angular';
import { CustomEnvironmentLoader } from './custom-environment.loader.ts';

EnvironmentModule.forRoot({ loader: CustomEnvironmentLoader });
  1. Using a provider.
import { Provider } from '@angular/core';
import { EnvironmentLoader } from '@kuoki/environment';
import { CustomEnvironmentLoader } from './custom-environment.loader.ts';

export const ENVIRONMENT_LOADER_PROVIDER: Provider = {
provide: EnvironmentLoader,
useClass: CustomEnvironmentLoader
};

Index

Classes

Generated using TypeDoc