加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 08:11:40 所属栏目:安全 来源:网络整理
导读:我正在通过关于指令的角度文档: http://docs.angularjs.org/guide/directive 页面上的一个例子(全部工作示例这里http://jsbin.com/osOQOYag/3/edit?html,output angular.module('docsTimeDirective',[]) .controller('Ctrl2',function($scope) { $scope.for
我正在通过关于指令的角度文档: 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读