Skip to content
Moe Myat Zaw edited this page Jun 5, 2020 · 14 revisions

Configuration Service for Angular

The ng-config is a configuration and options service for Angular applications with flexible and extendable config providers.

Get Started

Installation

npm

npm install @dagonmetric/ng-config

or yarn

yarn add @dagonmetric/ng-config

Module Setup

The following code is a simple module setup.

import { ConfigModule } from '@dagonmetric/ng-config';
import { HttpConfigProviderModule } from '@dagonmetric/ng-config/http-config-provider';

@NgModule({
  imports: [
    // Other module imports

    // ng-config module
    ConfigModule.init(),
    HttpConfigProviderModule.withOptions({
        endpoint: '/appsettings.json'
    })
  ]
})
export class AppModule { }

Usage

import { Component } from '@angular/core';

import { ConfigService } from '@dagonmetric/ng-config';

export class IdentityOptions {
  popupRedirectUri = ';
  automaticSilentRenew = true;
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  constructor(private readonly configService: ConfigService) {
    // Get with key
    const configValue = this.configService.getValue('key1'));
    console.log('configValue: ', configValue);

    // Get with options class
    const identityOptions = this.configService.map(IdentityOptions));
    console.log('identityOptions: ', identityOptions);

    // Change detection
    this.configService.valueChanges.subscribe(()=> {
      const lastestOptions = this.configService.map(IdentityOptions));
      console.log('lastestOptions: ', lastestOptions);
    });
  }
}

More Topics

Clone this wiki locally