Angular $ http post changes date format

The following situation:

I have a form with a field input[date]. I convert the values ​​with the following code:

$scope.entity.date = $filter('date')($scope.entity.date, 'yyyy-MM-dd');

This correctly formats the date, for example. 2015-10-27

When I submit an object using $http.postangular, it seems to recognize this as a date and reformat it before 2015-09-30T23:00:00.000Z. I am in Germany and we have GMT + 1. Thus, angular converts the date to GMT. Is there any way to disable this behavior?

Edit:

HTML code:

<form ng-submit="submit()">
  <input type="date" ng-model="entity.date" />
</form>

JS code:

$scope.submit = function() {
  $scope.entity.date = $filter('date')($scope.entity.date, 'yyyy-MM-dd');

  // when debugging this is the point where $scope.entity.date is 2015-10-27
  // so it is the format and date I expect

  $http({
    data: $scope.entity,
    method: POST,
    url: '/resource'
  })
    .success(function(data) {
      // do some stuff
    });

  // when looking into network traffic the request was sent with
  // 2015-09-30T23:00:00.000Z as value for $scope.entity.date
};
+4
source share
1 answer

. - , . , .

, , , . , , .

var entity = angular.copy($scope.entity);

, .

 $http({
    data: entity,
    method: POST,
    url: '/resource'
  })
+3

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


All Articles