HTML CODE
<div>
<label for="date">Update Time:</label>
<input id="date" ng-model="formData.Updt_Time" ng-value="ts">
</div>
这里我试图将ng-model和ng-value分配给输入字段,因为我的值(ng-value =“ts”)这个 ts 会来自我的控制器,我将不得不将数据保存到formData。在表单提交上,我将把set formData中的所有值插入到mySQL中。
控制器代码
clientApp.controller('formCtrl',function($scope,$http){
$scope.statuses = ["Active", "Inactive"];
$scope.cluster = ["East Coast","West Coast","PayPal"]
// Update Date
var currentTime = new Date()
var yr=currentTime.getFullYear()
var mnth=currentTime.getMonth()
var dt=currentTime.getDate()
if (mnth < 10) {
mnth = "0" + mnth
}
if (dt < 10) {
dt = "0" + dt
}
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()
if (minutes < 10) {
minutes = "0" + minutes
}
if (seconds < 10) {
seconds = "0" + seconds
}
$scope.ts = yr + "-" +mnth+ "-" + dt + " " + hours + ":" + minutes + ":" + seconds + " ";
//when submit button is clicked
$scope.submit = function() {
alert("Submit Clicked");
$http.post('/clientPost', $scope.formData).success(function(response) {
console.log('Data posted successfully');
})
.error(function(data){
console.log("There is an error");
console.log('Error: ' + data);
});
};
});
ng-model和ng-value似乎无法协同工作。有没有解决方法。
答案 0 :(得分:2)
首先我提出一些建议:
现在,根据我的理解,您尝试将文本框的值设置为格式化日期,并将其存储在变量 ts 中。
要设置文本框的值以及模型的值,您可以直接将 ts 的值设置为模型,这会导致Angular更新文本框的值
DrawerLayout