如何从 typeScript 中的事件中取出 Id?
How to take Out Id From Event in typeScript?
HTML:-
<ion-checkbox color="dark" checked="false" id="1on" (ionChange)="onTap($event)" ></ion-checkbox>
打字稿:-
onTap(e)
{
console.log(e);
console.log(e.checked);
}
我想获取复选框的 ID,我该如何获取它?
当我访问事件时,我可以看到里面有 elemtRef 里面有 nativeElement 里面有 id?所以如何访问 id 并在 console.log 上打印它不能在 ts 文件中使用 ajax。
因为您有对 DOM 元素的引用。试试这个:
const checkboxId = e.currentTarget.getAttribute('id');
这有效:
console.log(e._elementRef.nativeElement.id);
HTML:-
<ion-checkbox color="dark" checked="false" id="1on" (ionChange)="onTap($event)" ></ion-checkbox>
打字稿:-
onTap(e)
{
console.log(e);
console.log(e.checked);
}
我想获取复选框的 ID,我该如何获取它?
当我访问事件时,我可以看到里面有 elemtRef 里面有 nativeElement 里面有 id?所以如何访问 id 并在 console.log 上打印它不能在 ts 文件中使用 ajax。
因为您有对 DOM 元素的引用。试试这个:
const checkboxId = e.currentTarget.getAttribute('id');
这有效:
console.log(e._elementRef.nativeElement.id);