【发布时间】:2021-01-27 12:37:29
【问题描述】:
我收到此错误“算术运算的右侧必须是“任何”、“数字”、“大整数”或枚举类型。”
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-convert',
templateUrl: './convert.component.html',
styleUrls: ['./convert.component.css']
})
export class ConvertComponent implements OnInit {
amount = 1;
from = 'USD';
to = 'GBP';
rate = '1.37';
// function for conversion.
convert(): number {
return this.amount * this.rate;
}
constructor() {}
ngOnInit(): void {}
}
【问题讨论】:
-
您的汇率是一个字符串..
-
无关,
from是 Typescript 中的保留字。您甚至之前已经使用了很多行。我会避免将其用作变量名。 -
它甚至在这里的漂亮打印中显示为蓝色
-
您的问题是什么?请更清楚您的问题。
-
@Daniel.Wang
error 'The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enumtype.'
标签: javascript angular currency