Two Way Data Binding (Calculations)

Viewed 261

I'm trying to divide my gain and lotSize variable using two-way data binding but I keep getting these two errors :

  1. The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type - (gain error)
  2. The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type (lotSize error)

I'm new to using these frameworks but I get the feeling its something really basic. Any help you guys could provide would be really appreciated.

import { Component } from '@angular/core';
import { NavController } from '@ionic/angular';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  splash = true;

  constructor(public navCtrl: NavController) {
    //Splash Animation Timer
    setTimeout(() => this.splash = false, 4500);
  }

  //Calculation Variables
  entryPoint : Number = 0;
  gain : Number = 0;
  loss : Number = 0 ;
  lotSize : Number = 0;
  buyOrSell : Number = 0;

  //Calculation function buying and selling
  calculate = () => {
      let  rewardPips = (this.gain / this.lotSize) ;
  }

}

This the Html :

<ion-item>
      <ion-label position="stacked"><b>Entry Point # :</b></ion-label>
      <ion-input type="number" id="entryPoint" placeholder="0.000" [(ngModel)] = "entryPoint" clearInput></ion-input>
    </ion-item>
    <ion-item>
      <ion-label position="stacked"><b>Desired Monetary Gain $ :</b></ion-label>
      <ion-input type="number" id="gain" placeholder="0.000" [(ngModel)] = "gain" clearInput></ion-input>
    </ion-item>
    <ion-item>
      <ion-label position="stacked"><b>Willing Monetary Loss $ :</b></ion-label>
      <ion-input type="number" id="loss" placeholder="0.000" [(ngModel)] = 'loss' clearInput></ion-input>
    </ion-item>
    <ion-item>
      <ion-label position="stacked"><b>Trading Lot Size # :</b></ion-label>
      <ion-input type="number" id="lotSize" placeholder="0.000" [(ngModel)] = 'lotSize' clearInput></ion-input>
    </ion-item>

    <!--Grid With Checkbow Options-->
    <ion-grid>
      <ion-radio-group [(ngModel)] = "buyOrSell">
        <ion-row>
          <ion-col>
            <ion-item >
              <ion-label><b>Buy</b></ion-label>
              <ion-radio slot="start" value = "1" color="secondary"></ion-radio>
            </ion-item>
          </ion-col>
          <ion-col>
            <ion-item  >
              <ion-label><b>Sell</b></ion-label>
              <ion-radio slot="start" value = "0" color="secondary"></ion-radio>
            </ion-item>
          </ion-col>
        </ion-row>
      </ion-radio-group>
    </ion-grid>
    <br>
    <ion-button (click)="calculate()" color ="secondary" class="ion-activatable ripple-parent Primary" expand="block" shape="round">
      <h2><b>Calculate</b></h2>
      <ion-ripple-effect type="unbounded"></ion-ripple-effect>
    </ion-button>

  </ion-card>
</ion-content>
1 Answers

Replace Number with number for your variables and check.

Number is a wrapper class for number primitive data type. This will help you to convert number representation to number types. Since you are not dealing with such any, so you can directly use the primitive data type number.

Related