[英]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.