首页 > 解决方案 > Angular:错误 - 算术运算的左侧必须是“any”、“number”、“bigint”或枚举类型

问题描述

我收到此错误:

ERROR in src/app/product/product.component.html(11,46): The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
src/app/product/product.component.html(11,46): The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

这是第 11 行错误引用:

<p><a (click)="addToBasket(product)" [routerLink]="[product/product.product_id]">Buy</a></p>

我感觉问题出在其他地方,但我不确定。任何人都可以提出任何解决此问题的建议吗?

标签: angular

解决方案


您的[routerLink]="[product/product.product_id]"语法错误。您应该将其更正如下:

[routerLink]="['/product/' + String(product.product_id)]"

您的路线应以/开头,并且您应该有类似的路径

{ path: product/:id, component: SomeComponent}

在你的 app.routing.ts 里面


推荐阅读