【发布时间】:2016-07-20 09:40:41
【问题描述】:
HTML 代码
<div>
<label for="date">Update Time:</label>
<input id="date" ng-model="formData.Updt_Time" ng-value="ts">
</div>
在这里,我尝试将 ng-model 和 ng-value 分配给输入字段,因为我是 ts 的值(ng-value="ts")来自我的控制器,我将不得不将数据保存到 formData。在提交表单时,我会将设置的 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 似乎不能一起工作。有没有解决办法。
【问题讨论】:
-
将输入模型引用设置为 $scope,如
标签: javascript mysql angularjs