Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • AngularJS Tutorial
  • AngularJS Directives
  • AngularJS Functions
  • AngularJS Filters
  • AngularJS Examples
  • AngularJS Interview Questions
  • Angular ngx Bootstrap
  • AngularJS Cheat Sheet
  • AngularJS PrimeNG
  • JavaScript
  • Web Technology
Open In App
Next Article:
Quiz App using Angular
Next article icon

Calculator App Using Angular

Last Updated : 04 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

This Calculator app will provide basic arithmetic functionalities such as addition, subtraction, multiplication, and division, with a clean and modern UI. It will be fully responsive and interactive, ensuring a great user experience across different devices.

This project is suitable for both beginners and experienced developers looking to enhance their skills in front-end development and Angular framework. In this article, we will explain how to create a basic calculator using Angular with a good user interface developed by using CSS, HTML, and Bootstrap.

Project Preview

Screenshot-2024-08-31-222553
Calculator App Using Angular

Prerequisites

  • Basic understanding of HTML, CSS and JavaScript.
  • Angular CLI

Approach For Creating Calculator App

  • Initialize a new Angular application using Angular CLI.
  • Integrate Bootstrap into our Angular project for responsive and styled components.
  • Develop a dedicated component to encapsulate our calculator's logic and UI.
  • Utilize HTML and Bootstrap classes to create the calculator layout.
  • Write TypeScript logic to handle arithmetic operations and user interactions.
  • Apply custom styles to enhance the visual appeal.

Steps to Create Calculator App using Angular

Step 1 : Initialize a New Angular Project

Open your terminal and run the following command to create a new Angular project

ng new calculator
cd calculator

Folder Structure

Screenshot-2024-08-31-222816
Folder Structure

Dependencies

"dependencies": {
"@angular/animations": "^18.2.0",
"@angular/common": "^18.2.0",
"@angular/compiler": "^18.2.0",
"@angular/core": "^18.2.0",
"@angular/forms": "^18.2.0",
"@angular/platform-browser": "^18.2.0",
"@angular/platform-browser-dynamic": "^18.2.0",
"@angular/platform-server": "^18.2.0",
"@angular/router": "^18.2.0",
"@angular/ssr": "^18.2.0",
"express": "^4.18.2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.10"
}

Step 2 : Integrate Bootstrap

Once project is created. We integrate Bootstrap framework in this application. For integrating Bootstrap here we use CDN links in the index html file.

HTML
<!-- src/index.html -->  <!doctype html> <html lang="en">  <head>     <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"           rel="stylesheet">     <script src=             "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>     <meta charset="utf-8">     <title>Calculator</title>     <base href="/">     <meta name="viewport" content="width=device-width, initial-scale=1">     <link rel="icon" type="image/x-icon" href="favicon.ico"> </head>  <body>     <app-root></app-root> </body>  </html> 

Step 3 : Business Logic

Once bootstrap framework is integrated then we need to develop the logic for implementing the calculator app using Angular. For we develop basic User interface in the app.component.html file and for good look we use bootstrap and css. Once basic is UI created then we develop the calculator logic in the app.component.ts file.

HTML
<!-- src/app/app.component.html -->  <div class="container mt-5">     <div class="row justify-content-center">         <div class="col-md-4">             <div class="card">                 <div class="card-body">                     <h2 class="text-center text-success">Calculator</h2>                     <input type="text" class="form-control mb-3 text-right" [value]="display" readonly>                      <div class="btn-group d-flex mb-2" role="group">                         <button class="btn btn-danger w-100" (click)="clear()">C</button>                         <button class="btn btn-success w-100" (click)="appendInput('/')">/</button>                     </div>                     <div class="btn-group d-flex mb-2" role="group">                         <button class="btn btn-success w-100" (click)="appendInput('7')">7</button>                         <button class="btn btn-success w-100" (click)="appendInput('8')">8</button>                         <button class="btn btn-success w-100" (click)="appendInput('9')">9</button>                         <button class="btn btn-success w-100" (click)="appendInput('*')">*</button>                     </div>                     <div class="btn-group d-flex mb-2" role="group">                         <button class="btn btn-success w-100" (click)="appendInput('4')">4</button>                         <button class="btn btn-success w-100" (click)="appendInput('5')">5</button>                         <button class="btn btn-success w-100" (click)="appendInput('6')">6</button>                         <button class="btn btn-success w-100" (click)="appendInput('-')">-</button>                     </div>                     <div class="btn-group d-flex mb-2" role="group">                         <button class="btn btn-success w-100" (click)="appendInput('1')">1</button>                         <button class="btn btn-success w-100" (click)="appendInput('2')">2</button>                         <button class="btn btn-success w-100" (click)="appendInput('3')">3</button>                         <button class="btn btn-success w-100" (click)="appendInput('+')">+</button>                     </div>                     <div class="btn-group d-flex mb-2" role="group">                         <button class="btn btn-success w-100" (click)="appendInput('0')">0</button>                         <button class="btn btn-success w-100" (click)="appendInput('.')">.</button>                         <button class="btn btn-primary w-100" (click)="calculate()">=</button>                     </div>                 </div>             </div>         </div>     </div> </div> 
CSS
/* src/app/app.component.css */  .card {     box-shadow: 0 4px 8px green;     border-radius: 10px; }  .card-body {     padding: 20px; }  .btn {     font-size: 1.2rem;     padding: 15px;     border: 1px solid white; }  .btn-group .btn {     border-radius: 0; }  .form-control {     font-size: 2rem;     padding: 10px;     border-radius: 5px; }  h2 {     margin-bottom: 20px; } 
JavaScript
// src/app/app.component.ts  import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router';  @Component({     selector: 'app-root',     standalone: true,     imports: [RouterOutlet],     templateUrl: './app.component.html',     styleUrl: './app.component.css' }) export class AppComponent {     title = 'calculator';     display: string = '';      appendInput(value: string): void {         this.display += value;     }      clear(): void {         this.display = '';     }      calculate(): void {         try {             this.display = eval(this.display);         } catch (e) {             this.display = 'Error';         }     } } 

Step 4 : Run the Application

Once development is completed. Now we need to run the angular application by using below command.

ng serve

Output


Next Article
Quiz App using Angular

E

eswarbe06sp
Improve
Article Tags :
  • Web Technologies
  • AngularJS
  • Angular-Projects

Similar Reads

  • BMI calculator using Angular
    In this article, we will create a BMI Calculator application using the Angular framework. A BMI calculator helps in determining the relationship between a person’s height and weight by providing a numerical value. This value categorizes the individual into one of four categories: underweight, normal
    4 min read
  • Quiz App using Angular
    We will be creating a Quiz application using the Angular framework. This app will allow users to answer multiple-choice questions and view their results interactively. We'll use Angular Material for a polished UI and implement responsive design to ensure it looks great on all devices. The applicatio
    5 min read
  • Movie App Using Angular
    We will be creating a Movie Search Engine using Angular. This application allows users to search for movies by entering keywords and fetching and displaying a list of movie results in card format. The search engine initially loads a default set of movies to showcase the functionality. Through this p
    5 min read
  • Meme Generator App using Angular
    Angular has become one of the, most popular frameworks for building dynamic web applications. In this project, we will build a simple yet entertaining Meme generator app using Angular. The app will fetch random memes from a public API and display them to the user. This project will help us understan
    5 min read
  • Joke generator App Using Angular
    Angular has become one of the most popular frameworks for building dynamic web applications. In this project, we build a simple yet entertaining Joke generator app using Angular. The app will fetch random jokes from a public API and display them to the user. This project will help us understand how
    4 min read
  • Quote Generator App Using Angular
    A Quote Generator App is a simple application that displays random quotes to users. It is a great project for practising Angular basics such as components, services, data and API integration. Here we develop a simple Quote Generator App using Angular. This application can able to display a new Quote
    6 min read
  • News App Using Angular
    We will be developing a News Application using the Angular framework. This interactive app will allow users to search for news articles and filter them by category. With a clean and responsive design, it will dynamically display articles, providing an engaging and user-friendly experience. The app w
    9 min read
  • Dice Rolling App Using Angular
    We will be developing a Dice Rolling Application using the Angular framework. This application will showcase how to implement interactive features with smooth animations and a responsive layout. We will use FontAwesome icons to represent dice faces and create an engaging user experience with a visua
    4 min read
  • AngularJS | Application
    Applications in AngularJS enable the creation of real-time Applications. There are four primary steps involved in creation of Applications in AngularJS: Creation of List for an Application. Adding elements in the List. Removing elements from the List. Error Handling Below are the steps for creations
    3 min read
  • Calculator App Using TypeScript
    A calculator app is a perfect project for practising TypeScript along with HTML and CSS. This app will have basic functionalities like addition, subtraction, multiplication, and division. It provides a clean and interactive interface for the user while using TypeScript to handle logic safely and eff
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences