2

I have a Html like this.

<select name="paymentList" class="form-control" tabindex=""
                        ng-focus="true"
                        ng-disabled="!showRoomPaymentList"
                        move-focus-by-enter-key
                        ng-model="paymentList"
                        ng-options="s.FromDate | date: 'dd-MM-yyyy' + ' To ' + s.ToDate|date:'dd-MM-yyyy'  for s in showRoomPaymentList track by s.PaymentDurationId"
                        ng-required="true">
                    <option value="">--Select Payment Duration--</option>
                </select>

Output like this: 01-06-2016 To 2016-06-30T00:00:00 But I want It like this 01-06-2016 To 30-06-2016

Second part date format not working how to solve?

2 Answers2

1

May be this solved your question but you have to convert your dates in controller using format function.

Please let me know if any changes needed snippet is working.

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


app.controller('Test', function($scope,$filter) {

  $scope.selected = null;
  $scope.items = [{
    name: 'a',
    value: 1,
    something: "xyz",
from:"2016-06-30T00:00:00",
to:"2016-06-30T00:00:00"
  }, {
    name: 'b',
    value: 2,
    something: "xyz",
from:"2016-06-30T00:00:00",
to:"2016-06-30T00:00:00"

  }, {
    name: 'c',
    value: 3,
    something: "xyz",
from:"2016-06-30T00:00:00",
to:"2016-06-30T00:00:00"

  }]


  $scope.show = function() {
    alert("selectec " + $scope.selected.name + ' with value ' + $scope.selected.value);
  }

  $scope.format = function(i) {
    return  $filter('date')(i.from, "dd/MM/yyyy") + " to "+$filter('date')(i.to, "dd/MM/yyyy");
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<html ng-app="app">

<body>
  <div ng-controller="Test">
    <select data-ng-options="i as format(i) for i in items" ng-model="selected">
    </select>
    <button ng-click="show()">press</button>
  </div>
</body>

</html>
khajaamin
  • 856
  • 7
  • 18
1

The solution is to pack 'subexpression with filter' in () as in (anydate|date:'yyyy').

So, in your case:

s.FromDate | date: 'dd-MM-yyyy' + ' To ' + s.ToDate|date:'dd-MM-yyyy' 

change to

(s.FromDate | date: 'dd-MM-yyyy') + ' To ' + (s.ToDate|date:'dd-MM-yyyy')

See http://jsfiddle.net/jsggspm0/

Łukasz
  • 2,131
  • 1
  • 13
  • 28