My page has a recurring issue with a PayPal button that fails to load half the time. I recently experienced this problem when refreshing the page 30 times in a row – it alternated working properly for 9 times, then failed to load for 11 consecutive times, and finally loaded successfully for 10 straight times. This inconsistency is leaving me completely perplexed, as the same issue occurs both in the testing environment and in the live version.
The following error is displayed when the button fails to load:
deposittest.component.ts:224 TypeError: Cannot read properties of undefined (reading 'nativeElement')
at deposittest.component.ts:218:36
at _ZoneDelegate.invoke (zone.js:368:26)
at Object.onInvoke (core.mjs:26321:33)
at _ZoneDelegate.invoke (zone.js:367:52)
at Zone.run (zone.js:129:43)
at zone.js:1257:36
at _ZoneDelegate.invokeTask (zone.js:402:31)
at core.mjs:25998:55
at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:25998:36)
at _ZoneDelegate.invokeTask (zone.js:401:60)
Below is a snippet of the TypeScript file with certain code portions removed:
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { loadScript, PayPalNamespace } from "@paypal/paypal-js";
@Component({
selector: 'app-deposittest',
templateUrl: './deposittest.component.html',
styleUrls: ['./deposittest.component.css']
})
export class DeposittestComponent implements OnInit {
// TypeScript code goes here
}
This is a segment from the HTML file associated with the TypeScript code:
// HTML code goes here
Any insights or suggestions regarding this issue would be greatly appreciated. Thank you.