All Projects → geeklearningio → gl-ionic2-env-configuration

geeklearningio / gl-ionic2-env-configuration

Licence: MIT license
An Ionic2 Service to load an environment specific configuration before everything else

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to gl-ionic2-env-configuration

ionic2-PreDB
Simple Ionic 2+ with pre-populated database starter project
Stars: ✭ 14 (-39.13%)
Mutual labels:  ionic, ionic2
build ionic2 app chinese
this is the chinese version of <build ionic2 app chinese>
Stars: ✭ 16 (-30.43%)
Mutual labels:  ionic, ionic2
chihu
ionic2-example <吃乎>一款美食app 🍜 ☕️ 🍦 (This is a support android and apple ionic2 case, a food app)
Stars: ✭ 64 (+178.26%)
Mutual labels:  ionic, ionic2
Ionic2 Rating
⭐️ Angular star rating bar. Built for Ionic 2+.
Stars: ✭ 177 (+669.57%)
Mutual labels:  ionic, ionic2
ionic-socialsharing-with-deeplinking-example
Ionic Social Sharing and Deep Linking example app. Complete Ionic Tutorial with free example app! Built for Ionic 3.
Stars: ✭ 16 (-30.43%)
Mutual labels:  ionic, ionic2
Growth Ionic
[v2.0 DEPRECATED, please update to Growth 3.0] Growth - App to help you Be Awesome Developer & Awesome Hacker
Stars: ✭ 2,200 (+9465.22%)
Mutual labels:  ionic, ionic2
ngrx-store-ionic-storage
Simple syncing between @ngrx/store and Ionic Storage.
Stars: ✭ 66 (+186.96%)
Mutual labels:  ionic, ionic2
Ionic2 Reddit Reader
Ionic 2 Sample App
Stars: ✭ 128 (+456.52%)
Mutual labels:  ionic, ionic2
sm-coal-app
这是一个使用Ionic2开发的集数据展示,交易,交流于一体的APP
Stars: ✭ 21 (-8.7%)
Mutual labels:  ionic, ionic2
ionic3-image-handling
In this ionic tutorial you will learn how to access the image gallery and take pictures from an ionic app. Also we will show you how to add a image cropper. This ionic tutorial includes a working ionic app example you can reuse for your needs.
Stars: ✭ 35 (+52.17%)
Mutual labels:  ionic, ionic2
Ionic2 Pokedex
🎮 Pokédex sample app developed with Ionic 2, Angular 2 and Apache Cordova. Using Pokéapi as source for data.
Stars: ✭ 143 (+521.74%)
Mutual labels:  ionic, ionic2
ionic-video-chat-support
Ionic 3 Video and Group Text Chat
Stars: ✭ 19 (-17.39%)
Mutual labels:  ionic, ionic2
Ionic3 Multilevelsidemenu
Ionic 3 demo of a two-level side menu.
Stars: ✭ 141 (+513.04%)
Mutual labels:  ionic, ionic2
Wooionic3
An eCommerce App for WooCommerce stores using Ionic 3.
Stars: ✭ 208 (+804.35%)
Mutual labels:  ionic, ionic2
Ionic3 Components
A project full of ionic 3 components and samples - to make life easier :)
Stars: ✭ 1,689 (+7243.48%)
Mutual labels:  ionic, ionic2
ionic3
This repository contains complete source code for Ionic 3 tutorial from https://ampersandacademy.com/tutorials/ionic-framework-3. I will try many Ionic 3 specific scripts and will write them as separate tutorial. You can follow this repo to get more tested and working script for the Ionic 3.
Stars: ✭ 21 (-8.7%)
Mutual labels:  ionic, ionic2
Ion Digit Keyboard V2
A digital keyboard plugin to use in Ionic 2 applications.
Stars: ✭ 97 (+321.74%)
Mutual labels:  ionic, ionic2
Chihu2
ionic2-example <吃乎2>混合开发-美食app 🍜 ☕️ 🍦 (This is a support android and apple ionic2 case, a food app)
Stars: ✭ 124 (+439.13%)
Mutual labels:  ionic, ionic2
Dianoia-app
Mobile (Ionic 3 - Angular 4) app about non-pharmaceutical activities and information for people with dementia.
Stars: ✭ 13 (-43.48%)
Mutual labels:  ionic, ionic2
ionic-hockeyapp
Need HockeyApp in your Ionic application, add this package!
Stars: ✭ 19 (-17.39%)
Mutual labels:  ionic, ionic2

Introduction

This is an environment configuration package for Ionic2. It allows you to dynamically load a json configuration file at the root of your app (www). This json will be loaded before everything else in your App.

Usecase

For example, in a continuous integration system, we often need different API endpoints between developpment, preproduction, production and so on. This system will allow you to change this kind of parameter in the configuration file without having to recompile your Typescript code all over.

Example

To make it simpler, this repository contains a test-app folder which follows the "How to use it section". So if you prefer reading the code, go ahead!

How to use it

Install the module

Install it with npm:

npm install gl-ionic2-env-configuration --save

Create or copy your configuration json file

Simple way

Add a env-configuration.json file in your www folder containing your env configuration variables. There is no required key needed, it's your configuration. It will surely contain your api url, your Google Analytics ID and more... To copy the right configuration for the right environment, you will need a copy executable, as explained in the next section.

Automatic way (use a copy executable)

I made a simpe executable that will copy the right configuration file for a specified environment: copy-env-config.js which is available here.

Here how to use it:

node copy-env-config.js --env YOURENV

This will copy the file src/env-configuration/YOURENV.json to www/env-configuration.json

Even more automatic

Just run this command before your ionic:serve or ionic:build command to specify the right environment configuration to copy. For example, to build you app in prod and serve in dev, just update your package.json scripts like that:

"ionic:build": "node copy-env-config.js --env prod | ionic-app-scripts build",
"ionic:serve": "node copy-env-config.js --env dev | ionic-app-scripts serve"

Use the module in your Ionic 2 app

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

// Import the module
import { GLIonic2EnvConfigurationModule } from 'gl-ionic2-env-configuration';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    IonicModule.forRoot(MyApp),

    GLIonic2EnvConfigurationModule // Import the module here
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: []
})
export class AppModule {}

Get the configuration in your app

import { Component } from '@angular/core';

// Import the module
import {EnvConfigurationProvider} from "gl-ionic2-env-configuration";

// Import your configuration typings
// You can specify a typing for your configuration to get nice and neat autocompletion
import {ITestAppEnvConfiguration} from "../../env-configuration/ITestAppEnvConfiguration";

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  // inject the EnvConfigurationProvider and specify the configuration typings
  constructor(private envConfiguration: EnvConfigurationProvider<ITestAppEnvConfiguration>) {
    let config: ITestAppEnvConfiguration = envConfiguration.getConfig();
    console.log(config); // And here you have your nice configuration
  }

}

How it works

This modules uses a specific way to load the EnvConfigurationProvider which basically tells Angular to wait for this provider to load the configuration json file before loading the rest. So for example, your API service will have the right endpoint even in its constructor.

To learn more about this specific loading, you can see this discussion and this GIST file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].