AngularJS Slip no 9 Solution

<html ng-app="employeeApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="EmployeeController">
<h1>Employee Registration Form</h1>
<form name="employeeForm" novalidate>
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" ng-model="employee.firstName" required>
<label for="lastName">Last Name:</label>
<input type="text" id="lastName" name="lastName" ng-model="employee.lastName" required>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob" ng-model="employee.dob" required max="{{ maxDate }}">
<label for="joiningDate">Joining Date:</label>
<input type="date" id="joiningDate" name="joiningDate" ng-model="employee.joiningDate" required max="{{ currentDate }}">
<label for="salary">Salary:</label>
<input type="number" id="salary" name="salary" ng-model="employee.salary" required min="1">
<div>
<label>Arithmetic Calculator:</label><br>
<input type="radio" id="add" name="operation" ng-model="selectedOperation" value="add"> Add
<input type="radio" id="subtract" name="operation" ng-model="selectedOperation" value="subtract"> Subtract
<input type="radio" id="multiply" name="operation" ng-model="selectedOperation" value="multiply"> Multiply
<input type="radio" id="divide" name="operation" ng-model="selectedOperation" value="divide"> Divide
</div>
<div ng-switch="selectedOperation">
<div ng-switch-when="add">Result: {{ employee.salary + employee.dob.getFullYear() }}</div>
<div ng-switch-when="subtract">Result: {{ employee.salary - employee.dob.getFullYear() }}</div>
<div ng-switch-when="multiply">Result: {{ employee.salary * employee.dob.getFullYear() }}</div>
<div ng-switch-when="divide">Result: {{ employee.salary / employee.dob.getFullYear() }}</div>
</div>
<button type="submit" ng-click="submitForm()" ng- disabled="employeeForm.$invalid">Submit</button>
</form>
<script>
var app = angular.module('employeeApp', []);
app.controller('EmployeeController', function ($scope) {
$scope.employee = {};
$scope.maxDate = new Date().toISOString().split('T')[0];
$scope.currentDate = new Date().toISOString().split('T')[0];
$scope.submitForm = function () {
// Submit logic here (not included in the example)
};
});

</script>
</body>
</html>

No comments:

Post a Comment