How to set end date as a current or today's date in angularjs?

☆樱花仙子☆ 提交于 2019-12-25 00:26:06

问题


all I want to filter the items like (Start and End Date) which are based on invoice_date using the date range functionality in meanjs app.

  • My problem is the date filter function are working perfectly in plunker and my localHost production but while pushing to server it's showing only up to May month data's if some invoice_date values date has been `2017-08-24 and 2017-07-27' these data is not displaying in table, I don't know where I did the mistake and what I have missed it ..... My Plunk

  • Please look at my plunker to reference.

  • I Have displaying invoice_date, so this is the field I want to use for filtering.

  • So what I exactly looking for, I want to filter the invoice_date as start date and end date : for example:- if we select start date like 24-05-2017 and end date is 24-08-2017 in table this two transaction only need to display or filter... so I have used date range filter to achieve this solution, but in server it's not working for us please help.

  • In my server if I select end date as today's date all data's are showing perfectly on the table, so I think the problem is based on these fields $scope.from = new Date(2014, 04, 30); $scope.to = new Date(2019, 08, 25);

  • So if We set end date as a current or today's date in default, I think
    the problem would be solved, so how to set today's date as a default to end date...

Controller:

 .filter('dateRange', function() {
    return function(records, dateKey, from, to) {
        return records.filter(function(record) {
            return !moment(record[dateKey], 'YYYY-MM-DD').isBefore(moment(from))
            && !moment(record[dateKey], 'YYYY-MM-DD').isAfter(moment(to));
        });
    };
})

Html:

<input type="date" class="form-control" name="from" ng-model="from">

<input type="date" class="form-control" name="to" ng-model="to" ng-bind="getDatetime | date:'yyyy-MM-dd'">

Filter:-

ng-repeat="data in  record | dateRange : 'invoice_date' : from : to"
  • I tried the ng-bind method to set default today's date to end date like following:-

In controller:-

$scope.getDatetime = new Date();

In Html:-

<lable>End Date</lable><input type="date" class="form-control" name="to" ng-bind="getDatetime | date:'yyyy-MM-dd'" ng-model="to">
  • I have created plunker for reference:- My plunker

    • Showing like the moment is not defined:-

来源:https://stackoverflow.com/questions/45959394/how-to-set-end-date-as-a-current-or-todays-date-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!