简体   繁体   English

如何在角度js年或月上应用范围日期过滤器?

[英]How to apply a range date filter on angular js year or month?

i am new to angular JS. 我是角度JS的新手。 i have a date formatted like that d MMM y. 我有一个日期格式为d MMM y. however i have two fields one is called from and other to that should filter the date as a rang based on year range or month range. 但是我有两个字段,一个是从调用的,另一个是基于年范围或月范围将date过滤为范围的。 her is how i sort the data. 她是我对数据进行排序的方式。

   <div class="transition-item col-md-12" ng-repeat="trn in Transactions">
<div  id="{{'containerOf'+trn.TrnID}}" class="expand-trigger" 
   ng-click="expandTrns('containerOf'+trn.TrnID,'contentOf'+trn.TrnID)">
   <span class="glyphicon glyphicon-plus"></span> 
   <span class="glyphicon glyphicon-minus"></span>
</div>
<div class="col-md-7 transition-desc"><span ng-class="{'glyphicon glyphicon-arrow-up green-clr': trn.TrnType , 'glyphicon glyphicon-arrow-down red-clr': !trn.TrnType}"></span> {{trn.TrnSubject}}</div>
<div class="col-md-2 transition-amount">{{trn.TrnAmount | currency}}</div>
<div class="col-md-2 transition-date"><small>{{trn.TrnDate | date:"EEE, d MMM y"}}</small></div>

her is the form 她是形式

<div class="left form-inline col-md-8">
                 <div class="col-md-5">
                  from :
                  <input class="form-control" type="text" ng-model="one">
                 </div>

                 <div class="col-md-5">
                   to :
                  <input class="form-control" type="number" ng-model="two">
                 </div>
                </div>
              </div>
              <div class="sorting">
                <div class="left ">
                Sort :
              </div>
              <div class="btn-toolbar">
                <div class="btn-group">
                  <a class="btn btn-primary" href="#fakelink"><span class="glyphicon glyphicon-arrow-up"></span></a>
                  <a class="btn btn-primary" href="#fakelink"><span class="glyphicon glyphicon-arrow-down"></span></a>
                </div>
              </div> <!-- /toolbar -->
              </div>
            </div>              

Try this: 尝试这个:

Moment range JS is really useful. 矩范围JS非常有用。

Click HERE to check it 点击这里查看

Your question is still unclear after edit so I'll try to guess that you want to filter a Date property of the collection with the input month range. 编辑后您的问题仍然不清楚,因此我将尝试猜测您要使用输入月份范围来过滤集合的Date属性。 Here's how to do that with filter : 这是使用filter的方法

<div class="transition-item col-md-12" ng-repeat="trn in Transactions | filter:inMonthRange">

inMonthRange is the custom filter function defined on scope to check the month of the date. inMonthRange是在范围上定义的自定义过滤器功能,用于检查日期的月份。

$scope.inMonthRange = function(t){
  return t.dateField.getMonth() + 1 >= $scope.from && t.dateField.getMonth() +1 <= $scope.to;
}

You can refer to this Plunker for a working example. 您可以参考该Plunker的工作示例。 Filtering on year is similar. 年份过滤类似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM