https://github.com/domirs/ng-config-module
Provide configuration options through meta tags.
https://github.com/domirs/ng-config-module
angular configuration
Last synced: 2 days ago
JSON representation
Provide configuration options through meta tags.
- Host: GitHub
- URL: https://github.com/domirs/ng-config-module
- Owner: domirs
- License: mit
- Created: 2019-02-27T15:00:36.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-02-03T04:50:14.000Z (about 3 years ago)
- Last Synced: 2026-04-04T10:53:35.572Z (2 days ago)
- Topics: angular, configuration
- Language: TypeScript
- Homepage:
- Size: 2.5 MB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ng-config-module [](https://github.com/domirs/ng-config-module/actions/workflows/ci.yml) [](https://badge.fury.io/js/ng-config-module)
Provide configuration options through meta tags.
Every property is returned as a `string`.
`numbers` and `boolean` must be cast in the application itself.
## Installation
First you need to install the npm module:
`npm install ng-config-module`
## Usage
### Import the `ConfigModule`
```typescript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ConfigModule, ConfigService } from 'ng-config-module';
import { AppConfig } from './app-config';
@NgModule({
imports: [BrowserModule, ConfigModule],
providers: [
{
provide: AppConfig,
useExisting: ConfigService
}
],
bootstrap: [AppComponent]
})
export class AppModule {}
```
### Create `AppConfig`
```typescript
export class AppConfig {
api?: string;
}
```
### Add configurations to `index.html`
```html
...
NgConfigModule
...
```
### Use the configuration
```typescript
import { Component, OnInit } from '@angular/core';
import { AppConfig } from './app-config';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
api?: string;
constructor(private config: AppConfig) {}
ngOnInit() {
this.api = this.config.api;
}
}
```