Angular

Angular How to Add Two Number

In this tutorials will teach How to add two numbers in Angular.

First you have to add the FormsModule inside the imports.

Create the new Components addnumbers

addnum.components.html

<form>

    <h1>Add Two Numbers</h1>

<div>
  <label >Number 1</label>
  <input type = "text"  name="num1" [(ngModel)] = "num1" class="form-control"  placeholder="Enter Num 1">

</div>

<div>
    <label >Number 2</label>
    <input type = "text"  name="num2"  [(ngModel)] = "num2" class="form-control"  placeholder="Enter Num 2">
  
  </div>
  <div >
    <label >Total</label>
    <input  class="form-control"  placeholder="Total" value="{{ result }}"> 

  </div>

<button  (click)="Total()" class="btn btn-primary mt-4">Submit</button>


</form>

addnum.components.ts

num1:string = ”;
num2:string = ”;
result:number=0;
Total()
{
this.result = parseInt(this.num1) + parseInt(this.num2);
}

Full code on the

addnum.components.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-addnum',
  templateUrl: './addnum.component.html',
  styleUrls: ['./addnum.component.scss']
})
export class AddnumComponent implements OnInit {

num1:string = '';
num2:string = '';
result:number=0;


Total()
{
  this.result = parseInt(this.num1) + parseInt(this.num2);
}

  constructor() { }

  ngOnInit(): void {
  }

}

i have attached the video link below. which will do this tutorials step by step

 

 

 

 

admin

Recent Posts

Which Frontend Framework to Use with Spring Boot?

Spring Boot is a powerful backend framework for developing Java-based web applications. Pairing it with…

4 hours ago

Is Java Spring Boot Still Relevant in 2025?

The Rise of Spring Boot As technology advances, frameworks and tools that developers depend on…

5 hours ago

How to Check Laravel Print Version: A Simple Guide

Laravel Print Version: An Essential Guide Laravel is a powerful PHP framework widely used for…

9 hours ago

How to Laravel cache clear

Laravel cache clear , you can use the Artisan command-line tool that comes with Laravel.…

22 hours ago

Installing Vue.js in Laravel Project

Vue.js is a powerful JavaScript framework for creating dynamic user interfaces, while Laravel is a…

22 hours ago

Do I Return in Void Function in Java?

In Java, a void function (or method) does not return any value. However, you can use the return statement…

1 day ago