Defensive design features for your angular application
JavaScript HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
src
test
.babelrc
.editorconfig
.eslintrc
.gitignore
.jscsrc
.travis.yml
CHANGELOG.md
LICENSE
README.md
bower.json
gulpfile.js
package.json

README.md

angular-defensive

Defensive design for your angular application

Travis build status Dependency Status devDependency Status

Install

npm install --save angular-defensive

OR

bower install --save angular-defensive

Including

angular.module('myApp', [..., 'ngDefensive'])

Defining a configuration

Configurations should be registered into a run block. You can add to a configuration as many cases as you want, they will be checked in the same order you added them (first in, first out).

.run(function(CheckPreset, DefensiveConfiguration) {
  DefensiveConfiguration.registerConfiguration('requiresNetwork')
  .addCase({
      caseName: 'noNetwork',
      templateUrl: 'templates/no-network.html',
      check: function() {
        return CheckPreset.noNetwork();
      }
  });
})
  • caseName : The name of the case, which you can later use in a controller to specify an action when the defensive template is shown
  • template : An inline defensive template to show when the check function returns true. Overrides any given templateUrl.
  • templateUrl : The url to a defensive template to show when the check function returns true
  • check : If it is a promise, when resolved, it will cause the given defensive template to be shown inside any element which uses the ng-defensive directive (it will not when the promise is rejected or never resolved). If it is a value, it will show the template when truethy.

Using the directive

<div ng-defensive="confName" ng-defensive-callbacks="callbacks">
  Normal content
</div>

Marking any DOM element with the ng-defensive directive will make it check all cases of that configuration in order, showing the first template matching the check function which returns true.