<a appMenuDropDown (click)="getSubMenuItems(menuItem)">
.......
</a>
What happens when an element has a directive (appMenuDropDown) listening for a click event and a click event handler (getSubMenuItems()) ? Which handler gets triggered first ? Handler in directive or getSubMenuItems() ?
@HostListener('click')
clickListener() {
let sourceElement = this.el.nativeElement;
....
}
The order of event handlers is explicitly undefined. Also if you have several directives on an element, the order they are added is not significant to the order event handlers are processed.
I think that in your case HostListener within directive will be always fired first
You can take a look at generateHandleEventMethod
method within compiler from source code
directives.forEach((dirAst, dirIdx) => {
...
});
boundEvents.forEach((renderEvent, renderEventIdx) => {
...
});
and here is generated component.ngfactory
View_AppComponent0.prototype.handleEvent_4 = function(eventName,$event) {
var self = this;
self.debug(4,2,4);
self.markPathToRootAsCheckOnce();
var result = true;
result = (self._AppMenuDropDownDirective_4_3.handleEvent(eventName,$event) && result);
if ((eventName == 'click')) {
var pd_sub_0 = (self.context.getSubMenuItems() !== false);
result = (pd_sub_0 && result);
}
return result;
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.