微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – 什么是dateFilter,哪里可以找到更多关于它?

我正在通过关于指令的角度文档: http://docs.angularjs.org/guide/directive

页面上的一个例子(全部工作示例这里http://jsbin.com/osOQOYag/3/edit?html,output

angular.module('docsTimeDirective',[])
  .controller('Ctrl2',function($scope) {
    $scope.format = 'M/d/yy h:mm:ss a';
  })
  .directive('myCurrentTime',function($interval,datefilter) {

    function link(scope,element,attrs) {
      var format,timeoutId;

      function updateTime() {
        element.text(datefilter(new Date(),format));
      }

      scope.$watch(attrs.myCurrentTime,function(value) {
        format = value;
        updateTime();
      });

      element.on('$destroy',function() {
        $interval.cancel(timeoutId);
      });

      // start the UI update process; save the timeoutId for canceling
      timeoutId = $interval(function() {
        updateTime(); // update DOM
      },1000);
    }

    return {
      link: link
    };
  });

在线上:

.directive('myCurrentTime',datefilter) {

我无法为我的生活找到有关.directive原型的任何信息,也无法在datefilter任何地方找到任何文档。此外,我知道datefilter是在AngularJS的未精简版本中找到的(尽管名称在缩小版本中消失)。任何人都可以提供一些有关datefilter和类似功能的指导(可能还有一个链接)?

日期过滤器文档在这里http://code.angularjs.org/1.2.5/docs/api/ng.filter:date

以下是说明过滤器注入的文档的一部分:http://code.angularjs.org/1.2.5/docs/guide/filter#using-filters-in-controllers-and-services

过滤器通常用于视图表达式({{myDate | date:’short’}}),但也可以在您的JS代码中使用。过滤器通过将字符串过滤器附加到过滤器名称(例如日期 – > datefilter)来注入。

app.controller('MyCtrl',function($scope,datefilter,lowercaseFilter){
  $scope.myDate = new Date();
  $scope.myDateFormatted = datefilter($scope.myDate,'shortDate');

  $scope.myString = 'Some String';
  $scope.myStringLowerCased = lowercaseFilter($scope.myString);
});

PLUNKER

原文地址:https://www.jb51.cc/angularjs/144429.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐