[英](click) event is not working only on IOS devices - angular 10 app
我注意到我的按鈕在 IOS 設備上不起作用,似乎沒有調用點擊事件。 在 windows、android、Linux 上一切正常。 由於我無法訪問任何我試圖在 browserStack 上調試它的 mac,所以每次我嘗試單擊按鈕時都會收到此錯誤:
ERROR TypeError: undefined is not an object (evaluating 't.path[4]')
我可能完全錯了,但我認為它可能與按鈕內部的 SVG 矩形有關(我將它用作進度條),在矩形加載事件中我正在訪問它以查找它的長度。 可能它被稱為“太早”,因此它無法正確訪問矩形。 以前我使用帶有setTimeout
的ngAfterViewInit
來管理相同的效果。
<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;
}
代碼:
https://github.com/mateuszkornecki/chess-clock/tree/master/src
現場演示:
https://mateuszkornecki.github.io/chess-clock/settings
重現步驟:
只需單擊帶有計數器的大按鈕之一,單擊后它應該開始計數。
我在幾個 IOS 設備上對其進行了測試,無論 IOS 版本如何,它都不適用於所有人。 那是我用 Angular 制作的第一個項目,所以我有可能犯了一個簡單的錯誤。 任何幫助將不勝感激!
我找到了問題的根源。 我試圖在 click 事件上使用event.path
數組。 看起來它在 Safari 上不可用。 我通過使用event.composedPath
而不是event.path
解決了這個問題
參考: https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.