Created
September 23, 2013 07:48
-
-
Save kohgpat/6667582 to your computer and use it in GitHub Desktop.
angular.js date filter using moment.js
This file contains 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
angular.module("app.users", ["ngResource"]).factory("Users", function($resource) { | |
return $resource("users.json", {}, {get: {method: "GET", isArray: true}}); | |
}); | |
angular.module("app.filters", []).filter("date", function() { | |
moment.lang("ru"); | |
return function(date) { | |
return moment(new Date(date)).format("L"); | |
}; | |
}); | |
angular.module("app", ["app.users", "app.filters"]); | |
function UsersCtrl($scope, Users) { | |
$scope.users = Users.get(); | |
} |
This file contains 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
<!doctype html> | |
<html lang="en" ng-app="app"> | |
<head> | |
<title>Date Filters</title> | |
<meta chartset="utf-8"> | |
<script type="text/javascript" src="src/js/moment+langs.min.js"></script> | |
<script type="text/javascript" src="src/js/angular.min.js"></script> | |
<script type="text/javascript" src="src/js/angular-resource.min.js"></script> | |
<script type="text/javascript" src="src/js/app.js"></script> | |
</head> | |
<body> | |
<div id="container" ng-controller="UsersCtrl"> | |
<h1>Users</h1> | |
<div id="filter"> | |
<input type="text" ng-model="userFilter.firstName" placeholder="First Name" /> | |
<input type="text" ng-model="userFilter.lastName" placeholder="Last Name" /> | |
<input type="text" ng-model="userFilter.email" placeholder="Email" /> | |
<input type="text" ng-model="userFilter.createdAt" placeholder="Created" /> | |
</div> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>First Name</th> | |
<th>Last Name</th> | |
<th>Email</th> | |
<th>Created at</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr ng-repeat="user in users | filter: userFilter"> | |
<td>{{user.firstName}}</td> | |
<td>{{user.lastName}}</td> | |
<td>{{user.email}}</td> | |
<td>{{user.createdAt | date}}</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
</body> | |
</html> |
This file contains 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
[ | |
{ | |
"firstName": "John", | |
"lastName": "Doe", | |
"email": "[email protected]", | |
"createdAt": "2010-10-13" | |
}, | |
{ | |
"firstName": "Alice", | |
"lastName": "Appleseed", | |
"email": "[email protected]", | |
"createdAt": "2011-12-12" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment