从html错误中将负数-1传递给文本数类型为1 |-1的方法
我的html:从html错误中将负数-1传递给文本数类型为1 |-1的方法,html,angular,typescript,Html,Angular,Typescript,我的html: <button (mousedown)="onMouseDown($event, -1)"></button> 当我将参数1传递给onMouseDown时,一切都正常 当我通过错误将-1传递给onMouseDown aot编译时: numbercontrol.component.html(11,11):“number”类型的参数为 不可分配给“vector”类型的参数 html似乎无法理解文字类型。我该怎么处理呢?试试这个 HTML 在这种特殊情况下,A
<button (mousedown)="onMouseDown($event, -1)"></button>
当我将参数1传递给onMouseDown时,一切都正常
当我通过错误将-1传递给onMouseDown aot编译时:
numbercontrol.component.html(11,11):“number”类型的参数为
不可分配给“vector”类型的参数
html似乎无法理解文字类型。我该怎么处理呢?试试这个
HTML
在这种特殊情况下,Angular Ivy与Union类型定义冲突。禁用它将是一个解决办法。试试下面的方法 tsconfig.ts
{
“角度编译器选项”:{
“使能常春藤”:错误,
...
}
}
direction:1 |-1->direction:numberMarc,谢谢你的回答。我应该只将方向限制为1和-1没有像1 |-1这样的类型,只需输入direction:number,如果您想确保输入是-1或1,请在函数的开头设置一个条件。为什么我不能使用literal numeric type()?您发布的代码工作正常:我使用视图引擎
onMouseDown(e: MouseEvent, direction: 1|-1) {
this.compute.emit(direction);
this._mouseDown.next({e, direction});
}
<button (mousedown)="onMouseDown($event, 1)">DIRECTION</button>
OR
<button (mousedown)="onMouseDown($event)">DIRECTION</button>
onMouseDown(e: MouseEvent, direction = -1) {
this.compute.emit(direction);
this._mouseDown.next({e, direction});
}