Reset data of a form using on-click directive of a button.
/////////HTML/////////////
<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">
<input name="firstname" type="text" ng-model="firstName" required>
<input name="lastname" type="text" ng-model="lastName" required>
<input name="email" type="email" ng-model="email" required>
<button ng-click="reset()">Reset</button>
</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>
///////////////////studentController////////////////
myApp.controller("studentController",function($scope)
{
$scope.reset=function()
{
$scope.firstName='Shekhar',
$scope.lastName='Nawale',
$scope.email='nawale.shekhar1@gmail.com'
};
});
////////Main.js//////////////
var myApp=angular.module("myApp",[]);
/////////HTML/////////////
<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">
<input name="firstname" type="text" ng-model="firstName" required>
<input name="lastname" type="text" ng-model="lastName" required>
<input name="email" type="email" ng-model="email" required>
<button ng-click="reset()">Reset</button>
</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>
///////////////////studentController////////////////
myApp.controller("studentController",function($scope)
{
$scope.reset=function()
{
$scope.firstName='Shekhar',
$scope.lastName='Nawale',
$scope.email='nawale.shekhar1@gmail.com'
};
});
////////Main.js//////////////
var myApp=angular.module("myApp",[]);
No comments:
Post a Comment