我正在嘗試在我的專案 Angular 10 中實作 @HostListener,但它不起作用。
按照我下面的代碼:
主頁.ts
import {
HostListener,
Directive
} from '@angular/core';
export class EnumComponent {
@Directive({ selector: 'input[ListManual]'})
@HostListener('mouseenter', ['$event.target']) onClick() {
console.log("hereeee")
//this.newTypeButtonClick();
}
}
主頁.html
<ng-template pTemplate="body" let-data>
<tr>
<td>
<input
...
ListManual
/>
</td>
<td>
<input
...
ListManual
/>
</td>
<td>
<input
...
ListManual
/>
</td>
</tr>
</ng-template>
我希望它在我單擊輸入并顯示日志時起作用。
任何幫助將不勝感激。
uj5u.com熱心網友回復:
您的語法已關閉。嘗試以下操作:
import { HostListener, Directive } from '@angular/core';
@Directive({ selector: 'input[ListManual]'})
export class EnumComponent {
@HostListener('mouseenter', ['$event'])
onClick(ev: MouseEvent) {
console.log("hereeee")
//this.newTypeButtonClick();
}
}
uj5u.com熱心網友回復:
我們可以假設您已經在模塊中注冊了指令并且您已經驗證它正在被插值嗎?也許在指令的建構式中放置一個控制臺陳述句?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/522015.html
標籤:节点.js有角度的
上一篇:基于子組件的角度顯示/隱藏父組件
