HTML CODEng-Modell und ng-Wert für das einzelne Eingabefeld gesetzt
<div>
<label for="date">Update Time:</label>
<input id="date" ng-model="formData.Updt_Time" ng-value="ts">
</div>
Hier i ng-Modells und ng-Wert in das Eingabefeld da im zuweisen den Wertes versuchen (ng-value = "ts") diese ts würde von meinem Controller kommen, und ich muss die Daten in FormData speichern. Auf dem Formular submit werde ich alle Werte aus dem set formData in mySQL einfügen.
Steuerungskode
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);
});
};
});
Wie auch immer die ng-Modell und ng-Wert scheint nicht zusammen zu arbeiten. Gibt es einen Workaround?
Setzen Sie den Eingabemodellverweis auf $ scope, wie –