Skip to content

Instantly share code, notes, and snippets.

@n33kware
n33kware / app.component.ts
Created July 31, 2019 01:13
Angular Application Component File Using CfgService
// app.component.ts
import { Component } from '@angular/core';
import { CfgService } from './cfg.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
@n33kware
n33kware / environment.ts
Last active July 31, 2019 01:07
Angular CLI environment file
import { AppCfg } from '../cfg.service';
/**
* enviorment has a type of AppCfg
*/
export const enviorment: AppCfg {
production: true
}
@n33kware
n33kware / app.module.ts
Created July 31, 2019 01:02
Angular Application Module providing the environment options
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { APP_CFG } from './cfg.service';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
@n33kware
n33kware / cfg.service.ts
Last active July 31, 2019 01:07
Configuration Service that makes Angular environment injectable
export const APP_CFG = new InjectionToken<string>('APP_CFG');
export interface AppCfg {
production: boolean;
// extra attributes
[id: string]: any;
};
@Injectable({
@n33kware
n33kware / app.component.ts
Last active July 31, 2019 01:14
Importing the environment options in a file
// app.component.ts
import { Component } from '@angular/core';
import { environment } from '../environments/environment'; // file path
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})