angular-defensive
v0.1.4
Published
Defensive design for your angular application
Downloads
6
Readme
angular-defensive
Defensive design for your angular application
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 showntemplate
: An inline defensive template to show when thecheck
function returnstrue
. Overrides any giventemplateUrl
.templateUrl
: The url to a defensive template to show when thecheck
function returnstrue
check
: If it is a promise, when resolved, it will cause the given defensive template to be shown inside any element which uses theng-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.