Giter Club home page Giter Club logo

ngconfig's Introduction

ngConfig

A simple configuration service for AngularJS 1 apps.

Copyright (C) 2015, Gil Fink [email protected]

Installation

You can choose your preferred method of installation:

Usage

Include ngConfig.js in your application.

<script src="components/ngConfig/ngConfig.js"></script>

Add the module ngConfig as a dependency to your app module:

var myapp = angular.module('myapp', ['ngConfig']);

configuration service

Use the APIs that the configuration service exposes to use your application configuration. In the API you have four functions:

  • init(): initializes the configuration service. If you are loading the configuration from file, by default the configuration service will look a file called config.json which exists in a config folder -'config/config.json'. Usage example:

    config.init().then(function() {
    
    });
  • isInitialized(): checks whether the configuration object was loaded into memory. Usage example:

    if (!config.isInitialized()) {
      config.init().then(function() {
    
      });
    }
  • getConfigByKey(key): retrieve a configuration according to the supplied key.

    var val = config.getConfigByKey('key');
  • setConfigOfKey(key, value): sets the configuration of the supplied key to new configuration. When you set the key in a scenario of loading the configurations from file, only the in-memory object is updated (the value isn't saved to the configuration file).

    config.setConfigOfKey('key', 'value');

You can configure the configuration file Uri by using the setConfigUri function when you configure your module.

var app = angular.module('app', ['ngConfig']);
app.config(['configProvider', function (configProvider) {
  configProvider.setConfigUri('config/yourFileName.json');
}]);

You can use localStorage to hold your configurations. Use useLocalStorageForConfig with an application prefix string to use localStorage.

var app = angular.module('app', ['ngConfig']);
app.config(['configProvider', function (configProvider) {
  configProvider.useLocalStorageForConfig('myAppName');
}]);

An example of a configuration file:

{
  "config1": 15,
  "config2": false,
  "config3": "config3",
  "config4": [],
  "config5": {}
}

As shown in the Following Post:

http://blogs.microsoft.co.il/gilf/2015/06/22/building-a-simple-angularjs-configuration-service/

License

Released under the terms of the MIT License.

ngconfig's People

Contributors

gilf avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.