How to get date value from angular shape

HTML

<div align="center" ng-controller="FormCtrl">
    <form name="form" ng-submit="submitForm()" novalidate>
        <input type="date" name="myDate" ng-model="myDate" value="myDate"/>
    </form>
</div>

Javascript

var app = angular.module('formExample', []);
app.controller('FormCtrl', function ($scope, $http) {
     $scope.myDate = new Date();
});

app.js

app.post('/', function (req, res) {
    var jtime = req.body.myDate;
    console.log(jtime);
});

Here the result (console.log) shows undefined. How to get the value of this date from angular js form.

+4
source share
2 answers

Deploy the function $scope.submitFormby creating an AJAX POST request using $http.post:

app.controller('FormCtrl', function ($scope, $http) {
    $scope.submitForm = function() {
        $http.post('/', {myDate: $scope.myDate});
    };     
});
+1
source
<div align="center" ng-controller="FormCtrl">
  <form name="form" ng-submit="submitForm()" novalidate>
     <input type="date" name="myDate" ng-model="myDate" value="myDate"/>
  </form>
</div>

Here type="date"adds dates collector in this field

As soon as you select a date using date picker ng-model="myDate", it will be collected with the selected date

0
source

All Articles