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);
});
这里结果(console.log)显示未定义。如何从角度js形式获取该日期值。
答案 0 :(得分:1)
使用$http.post
实现$scope.submitForm
函数发出AJAX POST请求:
app.controller('FormCtrl', function ($scope, $http) {
$scope.submitForm = function() {
$http.post('/', {myDate: $scope.myDate});
};
});
答案 1 :(得分:0)
<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>
此处type="date"
将日期选择器添加到该字段
选择日期到日期选择器ng-model="myDate"
将按选定日期收集