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

0.1.2 • Public • Published

ng-environmenter

Angular environment sharing done easy

Getting started

Install the package: npm install ng-environmenter

Environment configuration

Create a environments folder at root level of your workspace, and a environment file for each environment, like the following:

// environments/environment.ts
export const globalEnvironment = {
  production: false,
};

And extend it on yours application environment file:

// projects/app/src/environments/environment.ts
import { Environment } from 'ng-environemnter';
import { globalEnvironment } from '../../../../environments/environment.ts';

export const environment: Environment = {
  application: {},
  global: globalEnvironment
};

Implementing the Environmenter

Add it to your AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { environment } from '../environments/environment';
import { EnvironmenterModule } from 'ng-environmenter';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    EnvironmenterModule.forRoot(environment)
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

And inject the Environmenter on any file:

import { Component } from '@angular/core';
import { Environmenter } from 'ng-environmenter';

@Component({
  selector: 'app-component',
  template: `
    <p>{{ getEnvironment() | json }}</p>
  `,
})
export class AppComponent {
  constructor(
    private environmenter: Environmenter
  ) {}

  getEnvironment() {
    return [
      this.environmenter.getApplicationEnvironment(),
      this.environmenter.getGlobalEnvironment(),
      this.environmenter.getEnvironment(),
    ];
  }
}

Package Sidebar

Install

npm i ng-environmenter

Weekly Downloads

15

Version

0.1.2

License

none

Unpacked Size

67.4 kB

Total Files

29

Last publish

Collaborators

  • klauskpm