简体   繁体   English

(点击)事件仅适用于 IOS 设备 - angular 10 应用程序

[英](click) event is not working only on IOS devices - angular 10 app

I noticed that my buttons are not working on the IOS devices, it seems that the click event is not called.我注意到我的按钮在 IOS 设备上不起作用,似乎没有调用点击事件。 Everything is working perfectly on the windows, android, Linux.在 windows、android、Linux 上一切正常。 Since I don't have access to any mac I was trying to debug it on the browserStack, I am getting this error every time I am trying to click the button:由于我无法访问任何我试图在 browserStack 上调试它的 mac,所以每次我尝试单击按钮时都会收到此错误:

ERROR TypeError: undefined is not an object (evaluating 't.path[4]')

I might be completely wrong, but I think that it might be related with the SVG's rect that is inside of the button (I am using it as a progress bar), on the rect load event I am accessing it to find its length.我可能完全错了,但我认为它可能与按钮内部的 SVG 矩形有关(我将它用作进度条),在矩形加载事件中我正在访问它以查找它的长度。 Maby it is called "too early" so it cannot access the rect correctly.可能它被称为“太早”,因此它无法正确访问矩形。 Previously I was using the ngAfterViewInit with the setTimeout inside to manage the same effect.以前我使用带有setTimeoutngAfterViewInit来管理相同的效果。

  <rect
    #rect
    width="96"
    height="96"
    rx="8"
    fill="none"
    stroke-width="4"
    [ngStyle]="{
      'stroke-dasharray': strokeDasharray,
      'stroke-dashoffset': strokeDashoffset
    }"
    (load)="getRectLength()"
  />
  getRectLength() {
    this.length = this.rect.nativeElement.getTotalLength();
    this.strokeDasharray = this.length;
  }

Code:代码:
https://github.com/mateuszkornecki/chess-clock/tree/master/src https://github.com/mateuszkornecki/chess-clock/tree/master/src

Live demo:现场演示:
https://mateuszkornecki.github.io/chess-clock/settings https://mateuszkornecki.github.io/chess-clock/settings

Steps to reproduce:重现步骤:
Simply click on one of the big buttons with the counter, after a click it should start counting.只需单击带有计数器的大按钮之一,单击后它应该开始计数。

I tested it on several IOS devices, it was not working on everyone regardless of the IOS version.我在几个 IOS 设备上对其进行了测试,无论 IOS 版本如何,它都不适用于所有人。 That's my first project made with Angular so there is a chance that I've made a simple mistake.那是我用 Angular 制作的第一个项目,所以我有可能犯了一个简单的错误。 Any help will be appreciated!任何帮助将不胜感激!

I have found the source of the problem.我找到了问题的根源。 I was trying to use the event.path array on the click event.我试图在 click 事件上使用event.path数组。 It looks that it is not available on the Safari.看起来它在 Safari 上不可用。 I fixed the problem by using the event.composedPath instead of the event.path我通过使用event.composedPath而不是event.path解决了这个问题

References: https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath参考: https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath

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

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