AngularJS Use Case – Shopping Cart Application

Here we are creating a shopping Cart Application and code for this application is as follows:

<html ng-app='scartApp'>
<script src=""></script>
<title>Shopping Cart</title>
<body ng-controller='SCartController'>
<h1>Shopping Cart Application</h1>
<table border = "1">
<td><b>Product Name</b></td>
<td><b>Total Price</b></td>
<tr ng-repeat="item in items">
<td><input ng-model='item.quantity'></td>
<td>{{item.price | currency}}</td>
<td> {{item.price * item.quantity | currency}}</td>
<td><button ng-click="remove($number)">Remove</button></td>
var sapp = angular.module('scartApp', []);
sapp.controller('SCartController', ['$scope', function($scope) {
$scope.items = [
{Name: 'Saree', quantity: 10, price: 100},
{Name: 'Mojari', quantity: 12, price: 40},
{Name: 'Bangles', quantity:8, price: 15},
{Name: 'Jeans', quantity:5, price: 20}
$scope.remove = function(number) {
$scope.items.splice(number, 1);
</html><button ng-click="remove($index)">Remove</button>
<script src="angular.js"></script>
function CartController($scope) {
$scope.items = [
{title: 'Paint pots', quantity: 8, price: 3.95},
{title: 'Polka dots', quantity: 17, price: 12.95},
{title: 'Pebbles', quantity: 5, price: 6.95}
$scope.remove = function(index) {
$scope.items.splice(index, 1);


Watch this Web Developer vs Web Designer video

Create a Shopping Cart Using AngularJS


  • <html ng-app> – It tells Angular which parts of the page it should handle.
  • <body ng-controller=’CartController’> – SCartController will handle everything between <body> and </body>.
  • <tr ng-repeat=”item in items”> – It creates an array of item.
  • <td>{{item.Name}}</td> – Display Product Name
  • <td><input ng-model=’item.quantity’></td> – The ng-model makes data binding between the input field and the value of quantity.
  • <td>{{item.price | currency}}</td> – Display the price of item in $ using currency tag.
  • <td> {{item.price * item.quantity | currency}}</td> – It displays the total price of the item which is the multiplication of price and quantity.
  • <button ng-click=‘remove ($index)’>Remove</button> – Creates a button remove. It will remove the item if you click on this button.
  • function SCartController($scope) { } – Manages the logic of this application.
  • $scope.items = [ ]; – It defines the collection of item for your shopping cart application.

Course Schedule

Name Date
Web Development Courses 2022-01-29 2022-01-30
(Sat-Sun) Weekend batch
View Details
Web Development Courses 2022-02-05 2022-02-06
(Sat-Sun) Weekend batch
View Details
Web Development Courses 2022-02-12 2022-02-13
(Sat-Sun) Weekend batch
View Details

Leave a Reply

Your email address will not be published. Required fields are marked *