Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a code based feature flag to the demo #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ If you need to *hide* elements when a flag is enabled, add the `feature-flag-hid
</div>
```

### Toggling CodeBlocks

The featureFlags.isOn method allows simple toggling of elements based on feature flags, e.g:

```javascript
if(featureFlags.isOn('code')) {
alert("Hello!");
}
```

### Running the demo

Running the demo is easy assuming you have Gulp installed:
Expand Down
6 changes: 6 additions & 0 deletions demo/data/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
"active": false,
"name": "Settings",
"description": "Configure the user's settings and preferences for the app."
},
{
"key": "code",
"active": true,
"name": "Code",
"description": "Code based flag"
}
]
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h1>My App</h1>
<div messaging feature-flag="messages"></div>
<div user-profile feature-flag="userProfile"></div>
<div settings feature-flag="settings"></div>
<code></code>
</div>
<div class="flagContainer" feature-flag-overrides></div>
</body>
Expand Down
17 changes: 17 additions & 0 deletions demo/scripts/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ angular.module('my-app')
replace: true
};
})
.directive('code', function(featureFlags) {
return {
restrict: 'E',
scope: {},
template: '<div class="panel"><button ng-click="codeCtrl.alert()">Click Me!</button></div>',
replace: true,
controllerAs: 'codeCtrl',
controller: function() {
var self = this;
self.alert = function() {
if (featureFlags.isOn('code')) {
console.log('Hello!');
}
};
}
};
})
.run(function(featureFlags, $http) {
featureFlags.set($http.get('../data/flags.json'));
});