Library allows you to provide environment variables externally for angular project. You are also allowed to change them after build.
npm install ng-environment --save
yarn add ng-environment
To allow external environment variables include .json
or .xml
file in assets
folder. Angular cli will copy these files to dist
folder after build.
import {EnvironmentModule} from 'ng-environment';
@NgModule({
declarations: [AppComponent],
imports: [EnvironmentModule.forRoot('assets/config.json')],
bootstrap: [AppComponent]
})
export class AppModule {}
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));
}
}