Skip to content

Instantly share code, notes, and snippets.

View anteburazer's full-sized avatar
💭
Ride hard live free

Ante Burazer anteburazer

💭
Ride hard live free
View GitHub Profile
const formDataMediaType = {
'Accept': 'application/json, text/plain, */*',
'content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
};
@POST("/products")
@Produces(MediaType.FORM_DATA)
@Headers(formDataMediaType)
@Adapter(CustomService.customAdapter)
function setEnvironment(configPath, environment) {
fs.writeJson(configPath, {env: environment},
function (res) {
console.log('Environment variable set to ' + environment)
}
);
}
// Set environment variable to "production"
setEnvironment('./src/config/env.json', 'production');
{ "env": "development" }
"scripts": {
"start": "npm run pre-start & ng serve",
"pre-start": "node hooks/pre-start.js",
"pre-build": "node hooks/pre-build.js",
"my-custom-build": "npm run pre-build & ng build --prod --aot"
}
{
"api": {
"baseUrl": "/api"
},
"debugging": true
}
@Injectable()
export class ConfigService {
private config: Object
private env: Object
constructor(private http: Http) {}
/**
* Loads the environment config file first. Reads the environment
let baseUrl: string = this.configService.get(api).baseUrl;
import { APP_INITIALIZER } from '@angular/core';
export function configServiceFactory (config: ConfigService) {
return () => config.load()
}
...
@NgModule({
...
providers: [
...
import { TranslateModule } from 'ng2-translate';
@NgModule({
imports: [
TranslateModule.forRoot()
],
});
translateService.get('HeaderTitle').subscribe(
value => {
let alertTitle = value;
}
)
let title = translateService.instant('HeaderTitle');