9.0.0 • Published 1 year ago

ng-config-module v9.0.0

Weekly downloads
98
License
MIT
Repository
github
Last release
1 year ago

ng-config-module CI npm version

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

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

export class AppConfig {
  api?: string;
}

Add configurations to index.html

...
<head>
  <meta charset="utf-8" />
  <title>NgConfigModule</title>
  <base href="/" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <link rel="icon" type="image/x-icon" href="favicon.ico" />
  <meta name="config" property="api" content="https://api.github.com" />
</head>
...

Use the configuration

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;
  }
}
8.0.0

2 years ago

9.0.0

1 year ago

7.0.1

3 years ago

6.0.1

3 years ago

5.0.0

3 years ago

4.0.0

4 years ago

3.0.2

4 years ago

2.0.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.2

5 years ago