0

I am binding mvc + json object with input control, but date is not formatting correctly

var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope, $http) {

    $scope.GetInitialData = function () {
        $(".load-bar").show();  

        $http({
            method: "get",
            url: "/ProjectClosure/GetInitialData"
        }).then(function (response) {
            $scope.projectData = response.data.projectData;           
        }, function () {
            alert("Error Occur");
        });
    };

});


<input type="datetime" class="form-control" name="CompletionDate" required placeholder="@ProjectResources.CompletionDate" ng-model="projectData.CompletionDate | date:'dd MMM yyyy'">

I expect date in 20 Aug 2019 format but it is displaying /Date(1566495000000)/

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Using the date pipe inside an ng-model expression makes no sense. The expression must be assignable for 2-wau binding to work. Angular can do `projectData.CompletionDate = newEnteredValue`. But it can't do `projectData.CompletionDate | date:'dd MMM yyyy' = newValue`. – JB Nizet Aug 24 '19 at 06:31
  • And the date filter doesn't support strings such as `/Date(1566495000000)/` anyway. Read its documentation. Use a decent, standard date format. (i.e. ISO-8601) – JB Nizet Aug 24 '19 at 06:32
  • check this question maybe can help https://stackoverflow.com/questions/14474555/how-to-format-a-date-using-ng-model – Emanuele Aug 24 '19 at 06:40

1 Answers1

0
  1. There is no input type="datetime" https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types
  2. This would need yyyy-mm-dd format as value and displays it depending on locale
  3. If you need time use input type="datetime-locale", but take a look at browser support first: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
Domenik Reitzner
  • 1,583
  • 1
  • 12
  • 21