0
votes

I am using Angularjs of version 1.1.5 and Angular UI-bootstrap of 0.6.0. I need to pass selected date in this yyyy-MM-dd format, but I am getting in "Tue Feb 03 2015 00:00:00 GMT+0530 (IST)" format. I have tried applying filters but that only changes {{dt}} value not ng-modal value hence in controller I am getting that Tue Feb 03 2015 00:00:00 GMT+0530 (IST) format.

I searched similar questions and tried solutions told in answers but no luck for me yet. Here is my code.

HTML code:

 <div class="row">
        <div class="">
            <p class="input-group">
              <input type="text" class="form-control" datepicker-popup="yyyy-MM-dd" ng-model="dt.date" is-open="opened" />
              <span class="input-group-btn">
                <button type="button" class="btn btn-default" ng-click="opencal($event)"><i class="fa fa-calendar"></i></button>
              </span>
              <span class="btn btn-xs btn-success input-group-addon" id="check_availability" ng-click="check_availability(dt.date)"><i class="fa fa-search"></i></span>
              <span class="btn btn-xs btn-warning input-group-addon" id="basic-addon2" ng-click="reset_halls()"><i class="fa fa-close"></i></span>
            </p>
        </div>Selected date {{dt.date}}
    </div>

JS code

app1.controller('HomeCtrl', function( $scope,$http,$q,$location,$window,$routeParams,$modal, $log) {
      $scope.opencal = function($event) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.opened = true;
      };
       $scope.check_availability=function(dt){
          alert("here I am getting date like this Tue Feb 03 2015 00:00:00 GMT+0530 (IST)"+dt);
          return $http({
            url:  'home/check_avail/'+dt,
            method: "POST"
          }).success(function(addData) {
                 $scope.hallinfo={};
                 $scope.hallinfo = addData;
          });
        }
    })

Here I have created plunker for you.

1

1 Answers

-1
votes

You could try something like this in the controller:

alert("Here I want date in yyyy-MM-dd format\n" + $filter("date")(sdate, "yyyy-MM-dd"));

and you should add a $filter param to the function:

app1.controller('HomeCtrl', function($scope, $http, $q, $location, $window, $modal, $log, $filter) { ...