angular - 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>
我感觉问题出在其他地方,但我不确定。任何人都可以提出任何解决此问题的建议吗?
解决方案
您的[routerLink]="[product/product.product_id]"语法错误。您应该将其更正如下:
[routerLink]="['/product/' + String(product.product_id)]"
您的路线应以/开头,并且您应该有类似的路径
{ path: product/:id, component: SomeComponent}
在你的 app.routing.ts 里面
推荐阅读
- ios - 检测 iOS 应用程序在没有观察者的情况下移动到后台
- c++ - Catch2 强制我在我的异常中添加对 std::string 的强制转换,这会产生其他问题吗?
- php - 为什么echo输出php结束标签?
- href - 在 Razor 页面上添加一个简单的 Href 标签以下载 .pdf 文件
- java - 如何切换二维数组中的两列?
- list - 如何在lisp中插入元素?
- highcharts - Highcharts DateTime 解析不正确
- angular - 在 Angular 应用程序中应该如何管理模态框/弹出窗口?
- c - What is the difference between pointer's address and the int value converted from pointer
- typescript - 如何在 typescript 中为泛型类编写扩展作为 getter