MA Rahman MA Rahman - 1 month ago 14
AngularJS Question

Angular validation error

i have two form of signup and login with code written under single controller with two function called on submit the first form work correctly but the signup always show errors
preview here in https://plnkr.co/edit/RS2LVc?p=preview

var app = angular.module('abc', []);
app.controller('login', function ($scope) {
scope.LoginValidator = function ($event) {
if ($scope.LoginForm.$valid) {
console.log('Logged In');
} else {
console.log("invalid");
if ($scope.LoginForm.Email.$invalid) {
$scope.mailRequire = true;
}
if ($scope.LoginForm.password.$invalid) {
$scope.passRequire = true;
}
$event.preventDefault();
}
};


then second function starts here and shows error

$scope.SignupValidator = function ($event) {

if ($scope.SignupForm.$valid) {
console.log("Valid");
} else {
alert('InValid Data');
if ($scope.SignupForm.Fullname.$invalid) {
$scope.namerequire = true;
}
if ($scope.SignupForm.email.$invalid) {
$scope.emailrequire = true;
}
if ($scope.SignupForm.rollno.$invalid) {
$scope.rollrequire = true;
}
if ($scope.SignupForm.password.$invalid) {
$scope.passwordrequire = true;
}
if ($scope.SignupForm.confirm.$invalid) {
$scope.confirmrequire = true;
}
$event.preventDefault();
}

};
});

Answer Source

It's working please check console it's print invalid