Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-feature-flags

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-feature-flags

Feature Flag module for Angular JS apps

  • 1.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status Coverage Status npm

angular-feature-flags

An AngularJS module that allows you to control when you release new features in your app by putting them behind feature flags/switches. This module only supports Angular v1.2 and up.

The idea

Abstracting your application functionality into small chunks and implementing them as loosely coupled directives. This allows you to completely remove sections of your application by simply toggling a single dom element.

How it works

The basic premise is you write your feature and wrap it up in a directive, then where you implement that directive in your markup you add the feature-flag directive to the same element. You can then pass the key of the flag to this directive to resolve whether of not this feature should be enabled.

The module pulls a json file down which defines the feature flags and which ones are active. If enabled angular will process the directive as normal, if disabled angular will remove the element from the dom and not compile or execute any other directives is has.

You can then add the override panel to your app and turn individual features on override the server values, saving the override in local storage which is useful in development.

Flag data

The flag data that drives the feature flag service is a json format. Below is an example:

[
    { "key": "...", "active": "...", "name": "...", "description": "..." },
    ...
]
keyUnique key that is used from the markup to resolve whether a flag is active or not.
activeBoolean value for enabling/disabling the feature
nameA short name of the flag (only visible in the list of flags)
descriptionA long description of the flag to further explain the feature being toggled (only visible in the list of flags)

Setting flag data

Flag data can be set via the featureFlags service using the set method. This currently accepts either a HttpPromise or a regular Promise. The promise must resolve to a valid collection of flag data.

For example, if you were loading your flag data from a remote JSON file:

var myApp = angular.module('app', ['feature-flags']);

myApp.run(function(featureFlags, $http) {
  featureFlags.set($http.get('/data/flags.json'));
});

Setting flag data on config phase (≥ v1.1.0)

From version v1.1.0 you can also initialize the feature flags in the config phase of your application:

var myApp = angular.module('app', ['feature-flags']);

myApp.config(function(featureFlagsProvider) {
  featureFlagsProvider.setInitialFlags([
    { "key": "...", "active": "...", "name": "...", "description": "..." },
  ]);
});

Toggling elements

The feature-flag directive allows simple toggling of elements based on feature flags, e.g:

<div feature-flag="myFlag">
  I will be visible if 'myFlag' is enabled
</div>

If you need to hide elements when a flag is enabled, add the feature-flag-hide attribute, e.g:

<div feature-flag="myFlag" feature-flag-hide>
  I will *NOT* be visible if 'myFlag' is enabled
</div>

Running the demo

Running the demo is easy assuming you have Gulp installed:

  • Checkout the project
  • Switch to the directory
  • Run 'gulp demo'

Should launch the demo in your default browser

Running the unit test

This relies on Gulp also obviously, to run the test suite:

  • Checkout the project
  • Switch to the directory
  • Run 'gulp test'

License

MIT

Keywords

FAQs

Package last updated on 21 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc