How can I reuse my Angular builds so I do not have to build for every specific environment?
we need to find a way to manipulate the environments in runtime in Angular!
We have settings for each environment and we use NG build --env=dev and build for the dev environment. How can I change the configuration in QA, UAT and production environments?
Toolset: .Net Visual Studio Team Services, Angular 2
Is there no way to do this at runtime? Are we stuck with the build time/design time?
Also can we consider selecting environments based on our urls which has a postfix ? https://company-fancyspawebsite-qa.azurewebsites.net
PS:We are using the Angular 2 environments folder and app settings files for each environment.
There are two main ways to create reusable components in Angular: Pass inputs to the component, passing the necessary data to the component used for rendering and configuring the component. This normally involves iterating over the provided data and follow a convention for how to render the data.
Introduction to Reusable Angular Components Every time you use a reusable component, you also have a parent component. This flexible content inside the reusable component comes from parent content and ends up in a dedicated slot inside the reusable component. So it is projected down to the parent component.
You can wrap each component inside an ngModule (as done by most ng component libs) and then use bit to share the component between two different projects or apps. The advantages are that you can publish, install and update individual components.
I use a config service to supply editable config settings at run-time. (this is using angular-cli)
config.service.ts
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@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 my src folder
{
"WebApiBaseUrl": "http://myWebApi.com",
"EnableConsoleLogging": true,
"PageSize": 10
}
add config.json to your assets in .angular-cli.json
{
},
"apps": [
{
"assets": [
"config.json"
]
}
}
}
how to use it
export class MyComponent {
private config: Config;
constructor(private configService: ConfigService) {
this.config = configService.getConfigSettings();
console.log(this.config.WebApiBaseUrl);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With