13

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).

4

1 回答 1

17

好的,像往常一样,我找到了答案。我做了:

angular.injector(["ng"]).get("$filter")("date");

没关系。

编辑

正如 meze 所观察到的,我也可以使用:

angular.injector(["ng"]).get("dateFilter")

货币数字过滤器的示例:

var filter = angular.injector(["ng"]).get("$filter")("number");

$('#Price').val(filter(price));
于 2013-10-02T10:51:37.603 回答