Final Angular JS Lab Manual - 21CSL581
Final Angular JS Lab Manual - 21CSL581
Final Angular JS Lab Manual - 21CSL581
BELAGAVI
Angular JS
Lab Manual (21-Scheme)
21CSL581
2023-24
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"
></script>
<body>
<br>
</div>
<script>
var app=angular.module('myApp',[]);
app.controller('myCtrl',function($scope){$scope.firstName="John";$scope.la
stName="Doe";});
</script>
</body>
</html>
OUTPUT:
2. Develop an Angular JS application that displays a list of shopping items. Allow
users to add and remove items from the list using directives and controllers.
Note: The default values of items may be included in the
program.
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<script type="text/javascript">
app.controller("myCtrl2", function($scope){
$scope.items=["chocolates","grocessories"];
$scope.addItem=function(){
$scope.items.push($scope.newItem);
$scope.newItem=""; };
if(index!=-1)
$scope.items.splice(index,1);
$scope.newItem="";
})
</script>
</head>
<h1>Shopping list</h1>
<button ng-click="addItem()">AddItem</button>
<button ng-click="deleteItem()">DeleteItem</button>
<ul>
</ul>
</div>
</body>
</html>
3. Develop a simple Angular JS calculator application that can Perform basic
mathematical operations(addition, subtraction,
multiplication, division) based on user input.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Number Calculator with AngularJS</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body>
<div ng-controller="CalculatorCtrl">
<h1>Lab Program 2 </h1>
<p>Enter the number:</p>
<input type="number" ng-model="number1">
<p>Enter another number:</p>
<input type="number" ng-model="number2">
<p>Addition:{{number1}}+{{number2}}={{number1+number2}}</p>
<p>Subtraction:{{number1}}-{{number2}}={{number1-number2}}</p>
<p>Multiplication:{{number1}}*{{number2}}={{number1*number2}}</p>
<p>Division:{{number1}}/{{number2}}={{number1/number2}}</p>
</div>
<script>
angular.module('myApp',[])
.controller('CalculatorCtrl',function($scope){
$scope.number1=0;
$scope.number2=0;
});
</script>
</body>
</html>
4. Write an AngularJS application that can calculate factorial and compute square
based on given user input.
<!DOCTYPE html>
<html>
<head><title>Lab 4</title>
<style>
div{
border: 1px solid black; margin:auto;width:50%;
padding: 5px; text-align:center;
}
</style>
</head>
<body ng-app="app1">
<div ng-controller="ctrl1">
<h1>Lab4-Square and Factorial</h1>
<p>Enter value 1: <input type="number"
ng-model="num1" default=10></p>
<p><button ng-click="calculate()">Calculate</button></p>
<h3>Factorial={{fact}}</h3>
<h3>Square={{square}}</h3>
</div>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
<script type="text/javascript">
var app = angular.module("app1", [])
app.controller("ctrl1", function ($scope) {
$scope.fact=2;
$scope.square=4;
$scope.num1=2;
$scope.calculate=function(){
$scope.fact=1;
for(i=1;i<=$scope.num1;i++)
$scope.fact=$scope.fact*i;
$scope.square=$scope.num1*$scope.num1;
}
})
</script></body></html>
5. Develop AngularJS application that displays a details of students and their CGPA.
allow users to read the number of students and display the count.
Note:Student details may be included in the program.
<!DOCTYPE html>
<html>
<head>
<title>Document></title>
<style>
#data{
margin:auto;
padding:10px;
width:50%;
text-align:center;
border:1px solid black;
}
table,th,td{
border:2px solid black;
border-collapse: collapse;
text-align: center;
align-self: stretch;
margin:auto;
}
</style>
</head>
<body ng-app="lab5" ng-controller="con5">
<div id="data">
<tr>
<th>Name</th>
<th>USN</th>
<th>Sem</th>
<th>CGPA</th>
</tr>
<td>{{stu.cgpa}}</td>
</tr>
</table>
</div>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
<script type="text/javascript">
var lab5=angular.module('lab5',[]);
lab5.controller("con5",function($scope){
$scope.students=[
name:"abc",usn:"3VC21CI001",sem:5,cgpa:9.5},
{name:"xyz",usn:"3vc21CI009",sem:3,cgpa:5.84}];
$scope.insert=function(){
$scope.students.push({name:$scope.name,usn:$scope.usn,sem:$scope.sem,cg
pa:$scope.cgpa});
}
})
</script>
</body>
</html>
6. Develop an AngularJS program to create a simple to-do list application.
allow users to add, edit, and delete tasks.
Note: The default values for tasks may be included in the program.
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></s
cript>
<style>
div{
margin: auto;
padding: 10px;
width: 50%;
text-align: center;
table,th,td{
border-collapse: collapse;
text-align: center;
align-self: stretch;
margin: auto;
padding: 5px;
</style>
</head>
<body>
<p>
</p><table>
<tr>
<th>Tasks</th>
<th>Operations</th>
</tr>
<tr ng-repeat="task in tasks">
<td style="text-align:left;">
<span ng-show="!task.editing">{{task.name}}</span>
<input type="text" ng-model="task.name" ng-show="task.editing">
</td>
<td>
<button ng-click="editTask(task)">Edit</button>
<button ng-click="deleteTask(task)">Delete</button>
</td></tr>
</table>
</div>
<script>
angular.module('lab6', [])
.controller('cntr6',function($scope){
$scope.tasks=[ {name:'Revise DBMS'},
{name:'Practice Angular Programs'},
{name:'Practice SQL Queries'},
{name:'Design one page of DBMS Project'} ];
$scope.addTask=function(){
$scope.tasks.push({name:$scope.newTask});
$scope.newTask='';
};
$scope.editTask = function(task) {
task.editing = !task.editing;
};
$scope.deleteTask=function(task){
var index=$scope.tasks.indexOf(task);
$scope.tasks.splice(index,1);
};});</script></body></html>
7. Write an AngularJS program to create a simple CRUD application(Create, Read,
update, and Delete)for managing users.
<!DOCTYPE html>
<html>
<head>
<title>User Management</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<style>
table{
width:100%;
border-collapse:collapse;
th,td{
th{
background-color:#f2f2f2;
button{
cursor:pointer;
</style>
</head>
<input type="text"
ng-model="newUser.name"placeholder="Name">
<input type="email"
ng-model="newUser.email"placeholder="Email">
<button type="submit"
ng-click="addUser()">Add User
</button>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>
<button ng-click="editUser(user)">Edit
</button>
<button
ng-click="deleteUser(user)">Delete
</button>
</td> </tr>
</table>
<script>
{id:1,name:'Rashi',email:'rashi@rymec.com'},
$scope.newUser={};
$scope.addUser=function(){
$scope.newUser.id=$scope.users.length+1;
$scope.users.push(angular.copy($scope.newUser));
$scope.newUser={}; };
$scope.editUser=function(user){
$scope.newUser=angular.copy(user); };
$scope.deleteUser=function(user){
var index=$scope.users.indexOf(user);
$scope.users.splice(index,1); }; });
</script>
</body>
</html>
8. Develop AngularJS program to create a login form, with validation for the
username and password fields.
<html ng-app="loginApp">
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
<body ng-controller="loginController">
<h1>Login Form</h1>
<form ng-submit="login()">
Username
<input type="text" ng-model="username" required>
<br>
Password
<input type="password" ng-model="password" required>
<br>
<button type="submit">Login</button>
</form>
<script>
var app = angular.module('loginApp', []);
app.controller('loginController', function ($scope) {
$scope.login=function(){
if($scope.username=='Arshad' && $scope.password == 'Ali') { alert('Login
successful');
}else{
alert('Login failed. Invalid username or password.');
}
};
});
</script>
</body>
</html>
Output1:
Output2:
9. Create an AngularJs application that displays a list of employees and their salaries.
Allow users to search for employees by name and salary.
Note:Employee details may be included in the program.
<html ng-app="employeeApp">
<head>
<title>AngularJS Employee Search</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
</head>
<body ng-controller="employeeController">
<h2>Employee List</h2>
Search by Name:
<input type="text" ng-model="searchName" />
Search by Salary:
<input type="number" ng-model="searchSalary" />
<ul>
<li ng-repeat="employee in employees | filter: {name: searchName, salary:
searchSalary}">
{{ employee.name }} - Salary: Rs{{ employee.salary }}
</li>
</ul>
<script>
var app = angular.module('employeeApp', []);
app.controller('employeeController', function ($scope) {
$scope.employees = [
{ name: 'Ram', salary: 50000 },
{ name: 'abi', salary: 60000 },
{ name: 'sam', salary: 75000 },
{ name: 'raj', salary: 55000 }
];
$scope.searchName = '';
$scope.searchSalary = '';
});
</script>
</body>
</html>
Output:
10. Create Angular JS application that allows users to maintain a collection of items.
The application should display the current total number of items, and this count
should automatically update as items are added or removed. Users should be
able to add items to the collection and remove them as needed. Note: The
default values for items may be included in the program.
<html ng-app="itemApp">
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
<body ng-controller="itemController">
<h2>Item Collection</h2>
<ul>
<li ng-repeat="item in items track by $index">
{{ item }}
<button ng-click="removeItem($index)">Remove</button>
</li>
</ul>
<script>
var app = angular.module('itemApp', []);
<html ng-app="studentApp">
<title>Student Name Converter</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
<body ng-controller="studentController">
<h2>Student Names</h2>
<h3>Original Names:</h3>
<ul>
<li ng-repeat="name in names">
{{ name }}
</li>
</ul>
<h3>Names in Uppercase:</h3>
<ul>
<li ng-repeat="name in names">
{{ name | uppercase }}
</li>
</ul>
<script>
var app = angular.module('studentApp', []);
app.controller('studentController', function ($scope) {
$scope.names = ['Raj', 'Ram', 'Sam'];
});
</script>
</body>
</html>
Output:
12. Create an AngularJS application that displays the date by using date filter parameters
<!DOCTYPE html>
<html ng-app="dateApp">
<head>
<title>Date Display Application</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
</head>
<body ng-controller="dateController">
<h2>Date Display</h2>
<p>Default Format: {{ currentDate | date }}</p>
<p>Custom Format (yyyy-MM-dd): {{ currentDate | date:'yyyy-MM-dd' }}</p>
<p>Short Date: {{ currentDate | date:'shortDate' }}</p>
<p>Full Date: {{ currentDate | date:'fullDate' }}</p>
<script>
var app = angular.module('dateApp', []);
app.controller('dateController', function ($scope) {
$scope.currentDate = new Date();
});
</script>
</body>
</html>
Output: