Skip to content

Commit 3025d53

Browse files
committed
2 parents 0184243 + aa8a8f7 commit 3025d53

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,76 @@
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.
16

7+
# Requirements
8+
- npm
9+
- angular
210

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`
314

15+
2) You can use the Typescript (`package/src/ConfigurationProvider.ts`) or the Javascript ((`package/dist/ConfigurationProvider.js`)) version of the Provider.
416

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']){
520
21+
}
22+
```
623

24+
# How to use
725

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+
```
833

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.
975

1076

0 commit comments

Comments
 (0)