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

Conditional Statements in Python

Conditional statements in Python allow us to control the flow of execution based on conditions.…

3 days ago

Java Beans

A Java Bean is a reusable software component that follows a specific set of conventions.…

1 week ago

Java String Methods

Java provides a rich set of built-in methods for handling String operations efficiently. Since strings…

1 week ago

Java Developer Jobs

Java remains one of the most in-demand programming languages worldwide, powering everything from enterprise applications…

1 week ago

Converting Integer to String in Java

Java provides multiple ways to convert an integer (int) to a string (String). Whether you're…

1 week ago

JSP to JSP Communication: A Complete Guide to Dynamic Java Web Development

Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…

2 weeks ago