简体   繁体   English

如何比较 Angular 中 tagName 和字符串的值?

[英]How to compare the value of a tagName and a string in Angular?

I try to find out when the tagname is "MAIN" an then to trigger some functions but unfortunately I steadily receive the error我试图找出标记名何时为“MAIN”,然后触发某些功能,但不幸的是我一直收到错误

This condition will always return true since the types "Event" and "Main" have no overlaps.由于“事件”和“主要”类型没有重叠,因此此条件将始终返回 true。

onMouseWheel(evt) {
event = evt.target.tagName;
while(event != 'MAIN')
  event = evt.target.parentNode.tagName;
}

Any ideas how I could achieve this?任何想法我怎么能做到这一点?

The angular approach to this is to attach the angular (wheel) directive to the element you're interested in and handle it that way.对此的角度方法是将 angular (wheel)指令附加到您感兴趣的元素并以这种方式处理它。

<main (wheel)="onMouseWheel($event)"></main>

This way the wheel event is only triggering the handler when it occurs on elements you're interested in.这样,wheel 事件只会在您感兴趣的元素上发生时触发处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM