npm.io
0.0.4 • Published 6 years ago

ng-environment

Licence
MIT
Version
0.0.4
Deps
0
Size
148 kB
Vulns
0
Weekly
0
Stars
1

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));
  }
}

Keywords