Angular 6 config file, read config on startup


0.0.64 years ago4 years agoMinified + gzip package size for @bondxge/config in KB



First, install it.

$ npm install @bondxge/config

Then add config.json file in assets.

Then, import it into your @NgModule:

import { ConfigModule } from '@bondxge/config';

imports : [

Then, use it in your component:

import { CONFIG } from '@lbge/config'; CONFIG.find('yourKey');

import { Injectable } from '@angular/core';
import { HttpRequest, HttpInterceptor, HttpHandler, HttpEvent, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { CONFIG } from '@bondxge/config';
import { tap } from 'rxjs/operators';

export class BaseUrlInterceptor implements HttpInterceptor {

    constructor() {

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        req = req.clone({
            url: CONFIG.find<string>('apiUrl') + req.url
        return next.handle(req);

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.