stripeService.ts
@ViewChild('cardElementForm', { static: false }) cardElementForm: ElementRef;
stripe = Stripe(environment.stripe.pubKey);
async initStripeElements() {
const elements = this.stripe.elements();
const cardElement = elements.create('card');
cardElement.mount(this.cardElementForm.nativeElement);
}
Note: I have included additional code. This is the service file that I am importing into my page component.
page.component.html
<form #saveCard="ngForm" class="saveCardForm">
<ion-item>
<div id="cardElementForm" #cardElementForm></div>
<ion-text *ngIf="error">{{ error }}</ion-text>
</ion-item>
<ion-item>
<ion-text (click)="this.payments.initStripeElements()">Initialize form</ion-text>
</ion-item>
<ion-item>
<ion-text (click)="this.payments.saveCard()">Submit data</ion-text>
</ion-item>
</form>
page.component.ts
import { PaymentService } from '../services/stripeService.ts';
I am encountering an error:
TypeError: this.cardElementForm is undefined
Can anyone help me identify where the issue lies? I seem to be stuck at this point.