Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ngx-config/http-loader

fulls1z31.1kMIT9.0.0TypeScript support: included

Loader for ngx-config that provides application settings using http

plugin, loader, http, configmodule, config, angular

readme

@ngx-config/http-loader npm version npm downloads

Loader for ngx-config that provides application settings using http

CircleCI coverage tested with jest Conventional Commits Angular Style Guide

Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.

Table of contents:

Getting started

Installation

You can install @ngx-config/http-loader using npm

npm install @ngx-config/http-loader --save

Note: You should have already installed @ngx-config/core.

Examples

The following packages may be used in conjunction with @ngx-config/http-loader:

Adding @ngx-config/http-loader to your project (SystemJS)

Add map for @ngx-config/http-loader in your systemjs.config

'@ngx-config/http-loader': 'node_modules/@ngx-config/http-loader/bundles/http-loader.umd.min.js'

Settings

Setting up ConfigModule to use ConfigHttpLoader

If you provide application settings using a JSON file or an API, you can call the forRoot static method using the ConfigHttpLoader. By default, it is configured to retrieve application settings from the endpoint /config.json (if not specified).

You can customize this behavior (and ofc other settings) by supplying a api endpoint to ConfigHttpLoader.

  • Import ConfigModule using the mapping '@ngx-config/core' and append ConfigModule.forRoot({...}) within the imports property of app.module.
  • Import ConfigHttpLoader using the mapping '@ngx-config/http-loader'.

Note: Considering the app.module is the core module in Angular application.

config.json

{
  "system": {
    "applicationName": "Mighty Mouse",
    "applicationUrl": "http://localhost:8000"
  },
  "seo": {
    "pageTitle": "Tweeting bird"
  },
  "i18n": {
    "locale": "en"
  }
}

app.module.ts

...
import { HttpClient } from '@angular/common/http';
import { ConfigModule, ConfigLoader,  } from '@ngx-config/core';
import { ConfigHttpLoader } from '@ngx-config/http-loader';
...

export function configFactory(http: HttpClient): ConfigLoader {
  return new ConfigHttpLoader(http, './config.json'); // API ENDPOINT
}

@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  ...
  imports: [
    ConfigModule.forRoot({
      provide: ConfigLoader,
      useFactory: (configFactory),
      deps: [HttpClient]
    }),
    ...
  ],
  ...
  bootstrap: [AppComponent]
})

ConfigHttpLoader has two parameters:

  • http: HttpClient : Http instance
  • endpoint: string : the API endpoint, to retrieve application settings from (by default, config.json)

:+1: Well! @ngx-config/http-loader will now provide application settings to @ngx-config/core using http.

License

The MIT License (MIT)

Copyright (c) 2019 Burak Tasci

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

9.0.0 (2020-04-27)

Features

  • package: migrate to ng9 (9370d36)

BREAKING CHANGES

  • package: ng9

8.2.0 (2020-04-27)

Features

8.0.2 (2019-12-02)

Bug Fixes

8.0.1 (2019-11-21)

Note: Version bump only for package @ngx-config/http-loader

8.0.0 (2019-11-21)

Features

  • package: upgrade to angular 8 (0d5161f)

BREAKING CHANGES

  • package: ng8