Date format The format is too complex when binding a value, AngularJS

I have a date picker in my angularJS WCFrest project

enter image description here

I get data using

<div class="col-md-4"> <input id="txtOldDate" type="date" class="datepicker" ng-model="oldDate" /> </div> 

but the data is too complicated when I get the data

Fri December 16, 2016 00:00:00 GMT + 07 (SE Asia Standard Time)

I just want to get the value as on the date picker interface

12/16/2016

this is my controller.js

 $scope.SearchApproval = function(employeeID, oldDate, newDate, departemen, approver) { var promiseGet = GetApproval.GetApprovalData($scope.employeeID, $scope.oldDate, $scope.newDate, $scope.departemen, $scope.approver); //GetApprovalData(); promiseGet.then(function(pl) { $scope.GetApprovalData = pl.data }, function(errorPl) { console.log('Some Error in Getting Records.', errorPl); }); } 

Is there a way to format the result?

I'm already trying $ filter

$ scope.oldDate = $ filter ('date') (new date (dateString), 'yyyy-MM-dd');

but he gives me this error

Error: [ngModel: datefmt] Expected 2016-12-20 as date

+6
source share
3 answers

Thanks for all your answer to help me.

Finally, I have already solved my own problem. Actually the problem is with the input type = "date". when I change it to type = "text". It can work to send only dates.

this is the result

 http://localhost:51458/ServiceRequest.svc/GetApproval?employeeID=&oldDate=2000-01-01 
0
source

Take a look at Angular Moment Js and Moment Js , this can be useful.

You can convert this to the following using js moment

 $scope.oldDate = moment(dateString).format("YYYY-MM-DD"); 

To use this, you must add an Angular momentum to your project and which is explained in the link above how to add using nuget or bower or npm.

+2
source

try it

  var mydate = $scope.oldDate.getFullYear()+ "-" + ($scope.oldDate.getMonth() + 1) + "-" + $scope.oldDate.getDate() 
0
source

Source: https://habr.com/ru/post/1013323/


All Articles