我正在使用SPA,当我们点击“保存”按钮时,我尝试将此字段设为必填项,但保存为空,我在使用ng-form
但不是form
这是我的代码:
event.html:
<div ng-form="eventForm" class="modal-content">
<div class="form-group">
<label>Place*</label> <input type="text" class="form-control" required
name="eventPlace" id="eventPlace" ng-model="eventVO.eventPlace" />
<div ng-show="eventForm.eventPlace.$touched">
<span ng-show="eventForm.eventPlace.$error.required">This
field is required.</span>
</div>
</div>
<a class="btn btn-success" ng-click="saveEvent()"
title="Click to save event">Save</a>
</div>
EventController.js:
$scope.saveEvent = function() {
debugger;
$scope.eventVO.userId = Session.userId;
$scope.eventVO.eventStartDate = moment($scope.eventVO.eventStartDate).format('YYYY-MM-DD HH:mm a');
$http({
url : "/event/add",
method : 'POST',
dataType : 'json',
'headers' : {
'Content-Type' : 'application/json'
},
data : $scope.eventVO
}).then(function(dataResponse) {
debugger;
if (dataResponse.data.status == "success") {
notify('Event saved successfully');
$(".add-event-modal").modal("hide");
$scope.getEvents();
$scope.clearModal();
} else {
notify('Error occured While Saving Event');
}
});
};
显示“此字段是必填项”,但在点击“保存”按钮时保存。如何强制使用此字段?
注意:点击保存时,我没有使用submit
。