简体   繁体   English

离子3-打字稿错误:算术操作数必须为“ any”,“ number”或枚举类型

[英]Ionic 3 - Typescript error: An arithmetic operand must be of type 'any', 'number' or an enum type

I have a click action when a user click on a like button for increment the number but when build or run the ionic app, i have a typescript error, can someone help me out with the solution? 当用户单击“喜欢”按钮以增加数字时,我会执行单击操作,但是在构建或运行离子应用程序时,我遇到打字稿错误,有人可以帮我解决该问题吗?

Typescript Error
An arithmetic operand must be of type 'any', 'number' or an enum type.
src/pages/comments/comments.ts
document.getElementById("like-" + commentid).innerHTML++

In comments.ts 在comments.ts中

likedislike(type,commentid) {
  if(type === 'like') {
    document.getElementById("like-" + commentid).innerHTML++
  }
}

Try to use Number() to cast the inner html string to number. 尝试使用Number()将内部html字符串转换为number。

var x = document.getElementById("like-" + commentid).innerHTML; 

document.getElementById("like-" + commentid).innerHTML = Number(x) + 1

It is way beter to do this with Angular data binding in Ionic though... 虽然这是用Ionic中的Angular数据绑定来做到这一点的方法,但是...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 算术操作数必须是“any”、“number”、“bigint”或枚举类型。ts(2356) - An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.ts(2356) TypeScript Boolean XOR -- 错误 TS2113:算术运算的左侧/右侧必须是“任何”、“数字”类型或枚举类型 - TypeScript Boolean XOR -- error TS2113: The left/right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type 打字稿。 如何在foreach循环中避免这个错误:“算术运算的左侧必须是'any','number'或枚举类型”? - Typescript. How to avoid this error in foreach loop: “left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type”? TypeScript“算术运算的左侧必须是'any'、'number'、'bigint'或枚举类型” - TypeScript “The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type” 可观察到的打字稿算术运算的左侧必须为“ any”,“ number”或枚举类型 - Typescript observable The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type 错误:算术运算的左侧必须是“任意”、“数字”或“枚举”类型的 Typescript 数组之间的乘法值 - Error: The left-hand side of an arithmetic operation must be of type 'any', 'number', or 'enum' Typescript multiplying value between array 错误TS2356说数字类型变量必须是“数字”类型的算术操作数 - error TS2356 says Number type variable must be an arithmetic operand of type 'number' TypeScript Generics 错误:算术运算的左侧必须是“any”、“number”、“bigint”类型 - TypeScript Generics error: left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' 按日期对数组进行排序时,算术运算的左侧必须是“any”、“number”、“bigint”类型或枚举类型错误 - The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type error when sort array by date Javascript 排序 Function 错误:'算术运算的右侧必须是'any'、'number'、'bigint'或枚举类型' - Javascript Sort Function Error: 'The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM