|
| 1 | +# Introduction |
| 2 | +This is a confuguration package for Angular. |
| 3 | +It allows you to dynamically load a json file at the root of your project. |
| 4 | +It also provides a provider that allows you to add configuration values in the config function of your Angular app. |
| 5 | +There is a test app using this Provider to show how to configure and use it. |
1 | 6 |
|
| 7 | +# Requirements |
| 8 | +- npm |
| 9 | +- angular |
2 | 10 |
|
| 11 | +# How to configure |
| 12 | +1) In your project folder, install this plugin using npm |
| 13 | +`npm install git+https://git@github.com/geeklearningio/gl-angular-configuration.git --save` |
3 | 14 |
|
| 15 | +2) You can use the Typescript (`package/src/ConfigurationProvider.ts`) or the Javascript ((`package/dist/ConfigurationProvider.js`)) version of the Provider. |
4 | 16 |
|
| 17 | +3) In your application's main module, inject the dependency `gl-angular-configuration` in order to use the Provider. |
| 18 | +``` |
| 19 | +angular.module('mainModuleName', ['ionic', 'gl-angular-configuration']){ |
5 | 20 |
|
| 21 | +} |
| 22 | +``` |
6 | 23 |
|
| 24 | +# How to use |
7 | 25 |
|
| 26 | +## Dynamically load the configuration.json file (optional) |
| 27 | +Add a `configuration.json` file at the root of your project. |
| 28 | +Remove the automatic bootstrap of your angular app. You can do it by Removing the `ng-app` tag of your `index.html` file. |
| 29 | +It will allow you to boostrap it manually after the json has been loaded. |
| 30 | +``` |
| 31 | +<html ng-app="testApp"> |
| 32 | +``` |
8 | 33 |
|
| 34 | +In your application's main module, call the `loadConfigurationJSON` and pass a callback as a param. In the callback, get the html dom element and bootstrap manually your app. |
| 35 | +``` |
| 36 | +loadConfigurationJSON(() => { |
| 37 | + var domElement = document.querySelector('html'); |
| 38 | + angular.bootstrap(domElement, ["testApp"]); |
| 39 | +}); |
| 40 | +``` |
| 41 | + |
| 42 | +## Add a configuration at config |
| 43 | +In the config function of your Angular application, inject the `ConfigurationProvider` and call the `addObject` function. |
| 44 | +You can specify the type of your configuration object in the Typescript version. |
| 45 | + |
| 46 | +``` |
| 47 | +import {ConfigurationProvider} from "gl-angular-configuration/package/src/ConfigurationProvider"; |
| 48 | +
|
| 49 | +interface ITestAppConfiguration { |
| 50 | + env: string |
| 51 | +} |
| 52 | +
|
| 53 | +export class Config { |
| 54 | + constructor(configurationProvider: ConfigurationProvider<ITestAppConfiguration>) { |
| 55 | + configurationProvider.addObject({otherParam: 'test'}); |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +## How to use the test app |
| 61 | +the test app does not have the package as a dependency. It allows you to make changes directly to the package and use it in your test app. |
| 62 | + |
| 63 | +You need to link the package locally. |
| 64 | +At the root of the project (containing the `package` and the `test-app` folders) type this in the terminal: |
| 65 | +``` |
| 66 | +npm link |
| 67 | +``` |
| 68 | +It will add `gl-angular-configuration` as a global npm module. |
| 69 | + |
| 70 | +Then go in the test-app folder and type this: |
| 71 | +``` |
| 72 | +npm link gl-angular-configuration |
| 73 | +``` |
| 74 | +It will link it to the test-app. |
9 | 75 |
|
10 | 76 |
|
0 commit comments