configuration - How to reuse the build for an Angular project -
how can reuse angular builds not have build every specific environment?
we need find way manipulate environments in runtime in angular!
we have settings each environment , use ng build --env=dev , build dev environment. how can change configuration in qa, uat , production environments?
toolset: .net visual studio team services, angular 2
is there no way @ runtime? stuck build time/design time?
i use config service supply editable config settings @ run-time. (this using angular-cli)
config.service.ts
import { injectable } '@angular/core'; import { http, headers, requestoptions, response } '@angular/http'; export interface config { pagesize: number; enableconsolelogging: boolean; webapibaseurl: string; } @injectable() export class configservice { private config: config; constructor(private http: http) { } public getconfigsettings(): config { if (!this.config) { var httpreq = new xmlhttprequest(); httpreq.open("get", 'config.json', false); httpreq.send(null); this.config = json.parse(httpreq.responsetext); if (this.config.enableconsolelogging) console.log("config loaded", this.config); } return this.config; } }
config.json located in src folder
{ "webapibaseurl": "http://mywebapi.com", "enableconsolelogging": true, "pagesize": 10 }
add config.json assets in .angular-cli.json
{ }, "apps": [ { "assets": [ "config.json" ] } } }
how use it
export class mycomponent { private config: config; constructor(private configservice: configservice) { this.config = configservice.getconfigsettings(); console.log(this.config.webapibaseurl); } }
Comments
Post a Comment