For each td element in a table I have an attached ng-click. Here is the (simplified) html for each table cell:
-
In Angular 7.x
myClickHandler($event) {
this.selectedElement = <Element>$event.target.closest('.list-item');
}
html:
<div class="list-item" (click)="myClickHandler($event)">...</div>
讨论(0)
-
Changing:
angular.element(event.target)
to:
angular.element(event.currentTarget)
fixed my issue.
It seems to me using event.currentTarget is preferred to event.target in the majority of usage cases.
讨论(0)
-
event.target.closest('td')
won't work because event.target
is a DOM element and it doesn't have method closest
. You need to create a jQuery object to use this method.
Try to find closest td
like this:
angular.element(event.target).closest('td')
讨论(0)
- 热议问题