bdt105angularconfigurationservice
TypeScript icon, indicating that this package has built-in type declarations

2.0.9 • Public • Published

Angular Configuration Service

Principle

Allows to read a configuration file before the angular app starts

Dependencies

bdt105toolbox (https://github.com/bdt105/modules/tree/master/toolbox)

Installation

In your app.module.ts insert

import { ConfigurationService } from 'bdt105angularconfigurationservice';
import { NgModule, APP_INITIALIZER } from '@angular/core';

...

export function init (config: ConfigurationService) {
    config.load();
    return () => {
        return config.load(); // add return
    };
}

@NgModule({
    declarations: [
        ],
    imports: [
        ],
    providers: [
        {
            'provide': APP_INITIALIZER,
            'useFactory': init,
            'deps': [ ConfigurationService ],
            'multi': true
        },
        ConfigurationService
        ],
    bootstrap: [AppComponent]    
});

...

providers: [ ConfigurationService ];

Into your component

import { ConfigurationService } from 'bdt105angularconfigurationservice';

...

constructor(private configurationService: ConfigurationService) {}

public getConfigurationBackgroungColor(){
    let conf = this.configurationService.get();
    return conf.backgroundColor;
}

Readme

Keywords

Package Sidebar

Install

npm i bdt105angularconfigurationservice

Weekly Downloads

1

Version

2.0.9

License

ISC

Unpacked Size

19.6 kB

Total Files

20

Last publish

Collaborators

  • bdt105