Skip to content

Instantly share code, notes, and snippets.

@jmwhittaker
Created November 26, 2012 12:47
Show Gist options
  • Save jmwhittaker/4148041 to your computer and use it in GitHub Desktop.
Save jmwhittaker/4148041 to your computer and use it in GitHub Desktop.
Something every Angular.js app should have
//mimic if statement for angular
//Schema: if(expression, 'foo', 'bar')
$scope['if'] = function(condition, a, b) {
return condition ? a : b;
};
//mimic switch case for angular
//Schema: switch(colorid, [[1,'red'], [2,'green'], [3, 'blue']], 'black')
$scope['switch'] = function (expression, cases, thedefault) {
for(var i = 0; i < cases.length; i++) {
var c = cases[i];
if(c[0] === expression) {
return c[1];
}
}
return thedefault;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment