【发布时间】:2015-05-05 09:25:51
【问题描述】:
我在我的项目中使用 AngularJS 和 Spring MVC。在此,我将 JSON 发送到其余控制器,该控制器验证字段并在验证失败的情况下返回错误对象,如下所示:
{"validationErrors":[
{
"errorCode":"emailId",
"errorDescription":"Please enter email address."
}
]}
现在,在jsp上如何显示内联错误信息?
我的jsp代码如下:
<label ng-model="emailLbl" for="userEmailID">Email ID</label>
<input type="email" ng-model="user.emailId" name="emailId" id="userEmailID" placeholder="Enter your email ID" />
//Here, I want to display inline error message
</div>
而我的 js 代码是: //更新 angular.module('MiniApp', []);
angular.module('MiniApp').controller('loginCtrl', ['$scope', '$http','$location',function($scope,$http,$location) {
$scope.loginSubmit = function(user) {
$scope.errors = [];
$scope.jsonObject = angular.copy(user);
var data1;
setTimeout(function(){
data1=document.getElementById("hiddenJson").value;
$http({
method: 'POST',
url: 'register1/login',
headers: {'Content-Type': 'application/json'},
data: data1
}).
success(function(data, status, headers, config) {
alert('Success:'+data.prospectResponseDetails.emailId+" - "+status);
$location.path('WEB-INF/pages/login-step1.jsp');
}).
error(function(data, status, headers, config) {
_showValidationErrors($scope, data.validationErrors);
$scope.errors = data.validationErrors;
});
$scope.getErrorMessage = function(errorCode) {
var error;
$scope.errors.forEach(function(error) {
if(error.errorCode === errorCode) {
error = error.errorDescription;
}
});
return error;
}
}, 200);
};
}]);
【问题讨论】:
-
应该学习一些角形教程
标签: javascript angularjs spring jsp spring-mvc