Here I'm using web API with AngularJS here I'm trying to if my keyup function is not valid then its shows me please select another email.
public IHttpActionResult GetEailCount(string email)
{
int obj= objrepo.countEmployee(email);
if (obj == 1)
return Ok("Email already exist please check another...");
else
return Content(HttpStatusCode.Accepted, "Email available..");
}
AngularJS:
<input type="text" name="emailtxt" ng-model="emailsId" ngkeyup="Getvaliedemail(emailsId)" required />
<span class="help-block" ng-show="(f1.emailtxt.Getvaliedemail.$valid)">Email exist</span>
Here how can I display Error msg based on my code
$scope.Getvaliedemail = function (someval) {
if (someval.length > 3) {
Empfac.Employemail(someval).then(function (d) {
$q.resolve(d);
}).catch(function (xhr) {
$q.reject(xhr);
})
}
}
})
EmployeeFactory.Employemail = function (mail) {
debugger;
alert()
return $http({
url: 'http://localhost:63252/Api/Home/GetEailCount/' + mail,
mathod: 'GET',
headers: {
"Content-Type": "application/json"
},
data: mail
})
}
You have to use
$asyncValidatorsfor this using a directive.Pay attention to
ng-show="f1.emailtxt.$error.Getvaliedemail".Remember, I'm assuming, your server will respond with
202status code means email does not exist and200status code means email exists.The code here will always fail the validation because the localhost URL is invalid and hence the rejection. Try with some real time server