Skip to content

Instantly share code, notes, and snippets.

@anth12
Last active August 29, 2015 14:05
Show Gist options
  • Save anth12/802549c652e0e9a63be4 to your computer and use it in GitHub Desktop.
Save anth12/802549c652e0e9a63be4 to your computer and use it in GitHub Desktop.
AngularJS Day of week filter
angular.module('example').filter('dayOfWeek', function() {
return function(dayIndex) {
switch(dayIndex) {
case 0:
return 'Sunday';
case 1:
return 'Monday';
case 2:
return 'Tuesday';
case 3:
return 'Wednesday';
case 4:
return 'Thursday';
case 5:
return 'Friday';
case 6:
return 'Saturday';
}
return '';
}
});
<div ng-app="example">
<table>
<tr>
<td>
{{ model.day | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 0 | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 1 | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 2 | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 3 | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 4 | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 5 | dayOfWeek}}
</td>
</tr>
<tr>
<td>
{{ 6 | dayOfWeek}}
</td>
</tr>
</table>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment