ngx-card
ngx-card copied to clipboard
How to get card type
How to get card type
Same here.
another request for returning the card type, works great in Ionic 4!
The card type is given in the classes in the number input field, along with various statuses
const creditCardElements = this.elementRef.nativeElement.querySelectorAll('.jp-card-logo');
creditCardElements.forEach(ccElement => {
if (window.getComputedStyle(ccElement).getPropertyValue('opacity') == 1) {
console.log(ccElement.classList[1].substring(8));
}
});
it logs 'visa'
Add Payment library on your .ts file
declare var Payment: any;
No need to import anything, it's already been included from ngx-card
And use as such to get card type,
let cardType = Payment.fns.cardType(this.cardNumber);
It returns the string representation of the card type. Eg. Visa, MasterCard etc.