0
votes

I am using the angular-ui bootstrap datepicker across an application and it works very well. However the backend I am sending the dates to only accepts dates in a given format, sadly this format is not what is the default that is put on the model for the date picker.

To combat this issue I have a few if checks that I run through before I persist the model. This does not scale very well on forms that have multiple dates.

if ($scope.dateOfBirthStr) {
  $scope.dateOfBirthStr = $filter('date')($scope.dateOfBirthStr, 'MM/dd/yyyy');
}

Without modifying the ui-datepicker itself is there an best practice I can use to format all the dates within a given model without having to call them out individually?

1

1 Answers

0
votes

I am not sure if I understand you correctly: You have problems converting the javascript Date used by the datepicker to a format your backend understands ?

What is the format your backend is accepting and how to you connect Angular to that backend? I personally use the the angular-ui datepicker with normal javascript Date objects ($scope.myDate = new Date() ... ) You should convert the dates only within the function that connects your angular-app to the backend.

(As I have node as a backend I never had that problem)