Created
November 26, 2012 12:47
-
-
Save jmwhittaker/4148041 to your computer and use it in GitHub Desktop.
Something every Angular.js app should have
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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