html - 将负数 -1 传递给文字数字类型为 1| 的方法 -1 来自 html 错误
问题描述
我的html:
<button (mousedown)="onMouseDown($event, -1)"></button>
我的ts:
onMouseDown(e: MouseEvent, direction: 1|-1) {
this.compute.emit(direction);
this._mouseDown.next({e, direction});
}
当我将参数 1 传递给 onMouseDown 时,一切正常当我通过错误将 -1 传递给 onMouseDown aot 编译时:
number-control.component.html(11,11): : 'number' 类型的参数不能分配给'vector' 类型的参数
似乎 html 无法理解文字类型。我该如何处理?
解决方案
在这种特殊情况下,Angular Ivy 与联合类型定义冲突。禁用它将是一种解决方法。尝试以下
tsconfig.ts
{
"angularCompilerOptions": {
"enableIvy": false,
...
}
}
推荐阅读
- c# - 将 API XML 消费到 csv 文件 C#
- android - Jetpack Compose:如何使用精确的 (x,y) 坐标在其父元素中定位 UI 元素?
- hash - 客户端代码签名技术讲解
- github-actions - Github Actions:在配置文件上触发以克隆存储库
- android - 如何自定义生成的二维码,如下图所示
- angular - 自动关闭角材料侧边菜单
- objective-c - 使用没有 ssl 的域 Objective-c
- python - 从栅格计算多边形平均值:rasterstats.zonal_stats 与 rio.clip
- python - 带有两个变量以匹配数字的 for 循环
- python - 无法从谷歌合作的雅虎财经获取数据