Develop an angular JS form to apply CSS and Events.
Create a file with any name like [Link]
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS Form with CSS and Events</title>
<link rel="stylesheet" href="[Link]">
<script
src="[Link]
<script src="[Link]"></script>
</head>
<body ng-controller="myCtrl">
<div class="form-container">
<h2>AngularJS Form</h2>
<form name="myForm">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" ng-model="[Link]" required>
<span ng-show="[Link].$touched && [Link].$invalid"
class="error">Name is required.</span>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" ng-model="[Link]" required>
<span ng-show="[Link].$touched && [Link].$invalid"
class="error">Valid email is required.</span>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" ng-
model="[Link]" required>
<span ng-show="[Link].$touched && [Link].
$invalid" class="error">Password is required.</span>
</div>
<div class="form-group">
<label for="gender">Gender:</label>
<select id="gender" name="gender" ng-model="[Link]" ng-
change="onGenderChange()">
<option value="">Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
<button type="submit" ng-click="submitForm()" ng-disabled="myForm.
$invalid">Submit</button>
<button type="button" ng-click="resetForm()">Reset</button>
</form>
<div ng-mouseover="onMouseOver()" ng-mouseleave="onMouseLeave()"
class="hover-box">
Hover over me!
</div>
</div>
</body>
</html>
2 Create a file for CSS applying with name [Link]
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.form-container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select {
width: 100%;
padding: 8px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
.error {
color: red;
font-size: 0.9em;
}
button {
padding: 10px 15px;
margin-right: 10px;
border: none;
border-radius: 4px;
background-color: #007bff;
color: white;
cursor: pointer;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
.hover-box {
margin-top: 20px;
padding: 15px;
background-color: #007bff;
color: white;
text-align: center;
border-radius: 4px;
cursor: pointer;
}
.hover-box:hover {
background-color: #0056b3;
}
3 Create other file with name [Link]
var app = [Link]('myApp', []);
[Link]('myCtrl', function($scope) {
$[Link] = {
name: '',
email: '',
password: '',
gender: ''
};
$[Link] = function() {
if ($[Link].$valid) {
alert('Form submitted successfully!\n' + [Link]($[Link], null, 2));
} else {
alert('Form is invalid. Please check the fields.');
}
};
$[Link] = function() {
$[Link] = {
name: '',
email: '',
password: '',
gender: ''
};
$[Link].$setPristine();
$[Link].$setUntouched();
};
$[Link] = function() {
[Link]('Gender changed to:', $[Link]);
};
$[Link] = function() {
[Link]('Mouse over the box!');
};
$[Link] = function() {
[Link]('Mouse left the box!');
};
});
When you run first file [Link] will get the following output
OUTPUT