0.0.4 • Published 4 years ago

ng-environment v0.0.4

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

ng-environment

Library allows you to provide environment variables externally for angular project. You are also allowed to change them after build.

Features

  • Accept the JSON and XML file.
  • Allow to Change the environment variables without new angular build.

Download and Installation

Step 1: Install ng-environment:

NPM

npm install ng-environment --save

YARN

yarn add ng-environment

Step 2: Include a JSON or XML file:

To allow external environment variables include .json or .xml file in assets folder. Angular cli will copy these files to dist folder after build.

Step 3: Import the EnvironmentModule:

import {EnvironmentModule} from 'ng-environment';

@NgModule({
  declarations: [AppComponent],
  imports: [EnvironmentModule.forRoot('assets/config.json')],
  bootstrap: [AppComponent]
})
export class AppModule {}

Step 4 : Access environment variables inside the components

Import EnvironmentService in the component

import {EnvironmentService} from 'ng-environment';
import {HttpClient} from '@angular/common/http';
  export class AppComponent {
  
  constructor(private http: HttpClient,private envService:EnvironmentService){
    this.dataRes();
  }

  public dataRes():void{
    this.http.get(`${this.envService.envConfig.apiUrl}employees`)
    .subscribe((res)=>{
      const resData =res;
    },(error)=>console.log(error));
  }
}