I want to format dates on the client-side using angular date filter. I'd like to do that way, because I use angular in some places of my application and I'd like my dates to be formatted uniformly in the whole app.
What I'm trying to do is:
function formatDatetime(date, format) {
var ngDateFilter = angular.getDateFilter(); //that's what I'm asking about
return ngDateFilter(date, format);
}
I use angular applications only on several pages, but dates are spread over various pages (with and without angular app).
OK, as usual I've found an answer. I did:
angular.injector(["ng"]).get("$filter")("date");
and it's OK.
EDIT
As meze observed, I could have also used:
angular.injector(["ng"]).get("dateFilter")
An example with number filter for currency:
var filter = angular.injector(["ng"]).get("$filter")("number");
$('#Price').val(filter(price));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With