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
import { TranslateModule } from 'ng2-translate';
@NgModule({
imports: [
TranslateModule.forRoot()
],
});
import { APP_INITIALIZER } from '@angular/core';
export function configServiceFactory (config: ConfigService) {
return () => config.load()
}
...
@NgModule({
...
providers: [
...
let baseUrl: string = this.configService.get(api).baseUrl;
@Injectable()
export class ConfigService {
private config: Object
private env: Object
constructor(private http: Http) {}
/**
* Loads the environment config file first. Reads the environment
{
"api": {
"baseUrl": "/api"
},
"debugging": true
}
"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"
}
{ "env": "development" }
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');
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)
@Injectable()
@DefaultHeaders({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
export class ProductsApiClient extends HttpService {
@PUT("/products/{id}")
public updateProductById(@Path("id") id: number, @Body product: Product): Observable<any> { return null; };
}