角度日期过滤器不使用ng-repeat

时间:2015-10-07 07:45:09

标签: javascript angularjs

控制器

app.controller("MarketController", function ($scope) {
    $scope.dates = [
        { date: Date.parse("01/01/1999"), value: 123.456 },
        { date: Date.parse("02/05/2004"), value: 789.123 }
    ];
});

模板

<li ng-repeat="item in dates">
    <span>{{item.date | date: 'EEE'}}</span>
</li>

日期值不适用于过滤器,我做错了什么?

2 个答案:

答案 0 :(得分:2)

它确实有效:

var app = angular.module('test', []);

app.controller("MarketController", function($scope) {
  $scope.dates = [{
    date: Date.parse("01/01/1999"),
    value: 123.456
  }, {
    date: Date.parse("02/05/2004"),
    value: 789.123
  }];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>

<div ng-app='test' ng-controller='MarketController'>
  <li ng-repeat="item in dates">
    <span>{{item.date | date: 'EEE'}} - {{ item.value }}</span>
  </li>
</div>

可能你拼错了ng-repeat

答案 1 :(得分:0)

尝试使用此功能进行日期过滤:

$filter('date')(date, 'yyyy.dd.MM');

不要忘记在此行注入$filter

..['$scope', '$filter', function($scope, $filter){...}