Skip to content
Permalink
Browse files

Added an example code

  • Loading branch information...
cedx committed Jun 4, 2019
1 parent 8f57bbc commit 81001e0b8170956e4389f96ff9c54191baeefd89
Showing with 42 additions and 0 deletions.
  1. +42 −0 example/main.ts
@@ -0,0 +1,42 @@
/* eslint-disable */
import {Component, NgModule, OnInit} from '@angular/core';
// @ts-ignore
import {appConfig, appEnv, Configuration} from '@cedx/ngx-core';

/** The application module. */
@NgModule({
providers: [
{provide: appConfig, useValue: {name: 'Core Library for Angular'}},
{provide: appEnv, useValue: 'production'}
]
})
class AppModule {}

/** A component that demonstrates the usage of the [[Configuration]] service. */
@Component({
selector: 'configuration-demo',
template: '<div></div>'
})
export class ConfigurationDemoComponent implements OnInit {
constructor(private config: Configuration) {}

ngOnInit(): void {
console.log(this.config.length); // 1
console.log(this.config.keys); // ["name"]
console.log(this.config.get('foo')); // undefined
console.log(this.config.get('name')); // "Core Library for Angular"

this.config.set('foo', 'bar');
console.log(this.config.length); // 2
console.log(this.config.keys); // ["name", "foo"]
console.log(this.config.get('foo')); // "bar"

this.config.remove('name');
console.log(this.config.length); // 1
console.log(this.config.keys); // ["foo"]
console.log(this.config.get('name', 'My Application')); // "My Application"

this.config.clear();
console.log(this.config.length); // 0
}
}

0 comments on commit 81001e0

Please sign in to comment.
You can’t perform that action at this time.