gpt4 book ai didi

angularjs - 如何从angularjs表单中获取日期值

转载 作者:搜寻专家 更新时间:2023-10-31 23:25:04 24 4
gpt4 key购买 nike

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)显示未定义。如何从 Angular js 表单中获取该日期值。

最佳答案

使用$http.post 实现$scope.submitForm 函数发出AJAX POST 请求| :

app.controller('FormCtrl', function ($scope, $http) {
$scope.submitForm = function() {
$http.post('/', {myDate: $scope.myDate});
};
});

关于angularjs - 如何从angularjs表单中获取日期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27499756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com