Tuesday, April 21, 2015

AngularJs check validation required

<html>
<title> AngularJs Directives </title>
<head>
<title>Angular JS Table</title>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>

<div ng-app="myApp">

<div ng-controller="studentController">

<form name="studentForm" novalidate>

<input name="firstname" type="text" ng-model="firstname" required>

<span style="color:red;" ng-show="studentForm.firstname.$error.required"> First Name Is required</span>

<input name="lastname" type="text" ng-model="lastname" required>

<input name="email" type="email" ng-model="email" required>

<button ng-click="reset()">Reset</button>

</form>

</div>


</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="main.js"></script>
<script src="studentController.js"></script>
</body>
</html>

////////////////Main.js///////////////////

var myApp=angular.module("myApp",[]);


////////////studentController//////////


myApp.controller("studentController",function($scope)
{
$scope.reset=function()
{
$scope.firstname='Shekhar',
$scope.lastname='Nawale',
$scope.email='nawale.shekhar1@gmail.com'
};
$scope.reset();
});

No comments:

Post a Comment