百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

angular-feature-flags

> 编程语言
开源

一个 AngularJS 模块,可用于在准备好之前隐藏/排除应用程序功能。

196 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个 AngularJS 模块,可用于在准备好之前隐藏/排除应用程序功能。

PSA: This repo is no longer maintained. Feel free to fork it to suit your use case.

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:

json
[
    { "key": "...", "active": "...", "name": "...", "description": "..." },
    ...
]
key
Unique key that is used from the markup to resolve whether a flag is active or not.




active
Boolean value for enabling/disabling the feature




name
A short name of the flag (only visible in the list of flags)




description
A 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:

javascript
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:

javascript
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:

xml

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

xml

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言