Angular typescript concatenating numbers instead of adding
Class
title = 'app';
a: number;
b: number;
c: number;
calc(): void {
this.c = this.a + this.b;
}
View
<input type="text" [(ngModel)]="a" (keyup)="calc()">
<input type="text" [(ngModel)]="b" (keyup)="calc()">
<p>{{c}}</p>
Return
if a = 1 and b = 2 for example it equal c = 12, it should be 3 and when i try parseInt(this.a) it result error Argument of type 'number' is not assignable to parameter of type 'string'.
number, then what the typescript is saying make sense. Changing the type to string should solve that issue.this.c=(+this.a)+(+this.b)