record prg angular
record prg angular
1. All those which we have done in lab are similar to VTU SYLL, only 3 program which given below are need
to be studied.
2. According to old manual which we use to practice neglect (1a,1b,2,4), leaving this study below
programs and write in record.
3. Below given 6th and 10 th program (to do list & item collection) are similar programs
3.Develop a simple Angular JS calculator application that can perform basic mathematical operations (addition,
subtraction, multiplication, division) based on user input.( this program is similar 1a from our old
manual )
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.j
s">
</script>
</head>
<body>
<h2> AngularJS Expression Example</h2>
<div ng-app="">
<p> Addition: 6 + 2 = {{6 + 2}} </p> <br />
<p> Subtraction: 6 - 2 = {{6 - 2}} </p><br />
<p> Multiplication: 6 * 2 = {{6 * 2}} </p><br />
<p> Division: 6 / 2 = {{6 / 2}}</p>
</div>
</center>
</body>
</html>
7. Write an AngularJS program to create a simple CRUD application (Create, Read, Update, and Delete) for
managing users.
<!DOCTYPE html>
<html ng-app="crudApp">
<head>
<title>AngularJS CRUD Application</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<form ng-submit="addUser()">
<label for="userName">Name:</label>
<input type="text" id="userName" ng-model="newUser.name" required>
<label for="userEmail">Email:</label>
<input type="email" id="userEmail" ng-model="newUser.email" required>
<script>
var app = angular.module('crudApp', []);
$scope.newUser = {};
$scope.addUser = function () {
if ($scope.newUser.name && $scope.newUser.email) {
$scope.users.push(angular.copy($scope.newUser));
$scope.newUser = {};
}
};
</body>
</html>
8. Develop AngularJS program to create a login form, with validation for the username and password
fields.
<!DOCTYPE html>
<html ng-app="loginApp">
<head>
<title>AngularJS Login Form</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<label for="password">Password:</label>
<input type="password" id="password" ng-model="password" ng-minlength="6" required>
<div class="error" ng-show="formSubmitted && loginForm.password.$error.required">Password is required.</div>
<div class="error" ng-show="formSubmitted && loginForm.password.$error.minlength">
Password should be at least 6 characters.
</div>
<button type="submit">Login</button>
<div class="error" ng-show="loginFailed">Invalid username or password.</div>
</form>
</div>
<script>
var app = angular.module('loginApp', []);
$scope.login = function () {
$scope.formSubmitted = true;
if ($scope.loginForm.$valid) {
if ($scope.username === validUsername && $scope.password === validPassword) {
// Authentication successful
console.log('Login successful!');
$scope.loginFailed = false;
} else {
// Authentication failed
console.log('Login failed!');
$scope.loginFailed = true;
}
}
};
});
</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 ng-app="todoApp">
<head>
<title>AngularJS To-Do List</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<form ng-submit="addTask()">
<label for="newTask">New Task:</label>
<input type="text" id="newTask" ng-model="newTask" required>
<button type="submit">Add</button>
</form>
<ul>
<li ng-repeat="task in tasks">
<span>{{ task }}</span>
<span>
<button ng-click="editTask($index)">Edit</button>
<button ng-click="deleteTask($index)">Delete</button>
</span>
</li>
</ul>
</div>
<script>
var app = angular.module('todoApp', []);
$scope.addTask = function () {
if ($scope.newTask.trim() !== "") {
$scope.tasks.push($scope.newTask);
$scope.newTask = "";
}
};
</body>
</html>
10. Create AngularJS 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.
<!DOCTYPE html>
<html ng-app="itemApp">
<head>
<title>AngularJS Item Collection</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<ul>
<li ng-repeat="item in items">
{{ item }}
<button ng-click="removeItem($index)">Remove</button>
</li>
</ul>
<script>
var app = angular.module('itemApp', []);
$scope.addItem = function () {
if ($scope.newItem.trim() !== "") {
$scope.items.push($scope.newItem);
$scope.newItem = "";
}
};
</body>
</html>
2) <!DOCTYPE html>
<html ng-app="shoppingListApp">
<head>
<title>AngularJS Shopping List App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script>
var app = angular.module('shoppingListApp', []);
app.controller('shoppingListCtrl', function ($scope) {
$scope.shoppingItems = ['Sugar', 'Milk', 'Flour'];
$scope.addItem = function () {
if ($scope.newItem) {
$scope.shoppingItems.push($scope.newItem);
$scope.newItem = '';
}
};
$scope.removeItem = function (index) {
$scope.shoppingItems.splice(index, 1);
};
});
</script>
</head>
<body>
<div ng-controller="shoppingListCtrl" id="shoppingListContainer">
<h2>Shopping List</h2>
<ul>
<li ng-repeat="item in shoppingItems">
<span>{{ item }}</span>
<button ng-click="removeItem($index)">Remove</button>
</li>
</ul>
<div>
<label for="newItem">Add New Item:</label>
<input type="text" id="newItem" ng-model="newItem" placeholder="Enter a new item">
<button ng-click="addItem()">Add Item</button>
</div>
</body>
</html>