我正在使用AngularJs。我在controller.js文件中創建了一條錯誤消息,並希望將錯誤消息發送到index.html。我已經使用了下面的代碼,但不知道如何將它傳遞給span元素,並從錯誤消息中刪除字符「,」。下面是使用的代碼:在jQuery中添加錯誤消息並在span中顯示+ AngularJs
//controller.js
$scope.isAllDateTimeMissing = false;
$scope.add = function() {
if (!$scope.mainForm.$valid) {
alert("Form is not valid")
}
else {
var msg = "Please select ";
if ((jQuery('#startDatepicker').val() == ""))
{
$scope.isAllDateTimeMissing = true;
msg = msg + "Start Date";
}
if((jQuery('#endDatepicker').val() == ""))
{
$scope.isAllDateTimeMissing = true;
msg = msg + ",End Date";
}
if ((jQuery('#startTimepicker').val() == ""))
{
$scope.isAllDateTimeMissing = true;
msg = msg + ",Start Time";
}
if ((jQuery('#endTimepicker').val() == ""))
{
$scope.isAllDateTimeMissing = true;
msg = msg + ",End Time";
}
};
我婉通過 「味精」 到index.html的,這是我目前有如下:
<span class="error" ng-show="submitted == true && isAllDateTimeMissing"></span>
而且,另一個問題是如果只有結束日期的值爲空,那麼我想從消息中刪除字符「,」。 如何做到這一點? 感謝