0.0.4 • Published 6 years ago
ng-environment v0.0.4
ng-environment
Library allows you to provide environment variables externally for angular project. You are also allowed to change them after build.
Features
Download and Installation
Step 1: Install ng-environment:
NPM
npm install ng-environment --saveYARN
yarn add ng-environmentStep 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));
}
}