Question
import { Directive, OnChanges, HostBinding } from @angular/core; import { NgOnChangesFeature } from '@angular/core/src/render3'; enum CardType { VISA = 'Visa' ,MASTERCARD = 'MasterCard',DISCOVER = 'Discover'
import { Directive, OnChanges, HostBinding } from "@angular/core";
import { NgOnChangesFeature } from '@angular/core/src/render3';
enum CardType { VISA = 'Visa' ,MASTERCARD = 'MasterCard',DISCOVER = 'Discover' ,UNKNOWN = 'Unknown'
@ Directive ({
selector:'[cLogo]'
})
export class CreditCardImageDirective implements OnChanges {
@HostBinding ('src')
imageSource;
cardNumber: number;
NGOnChangesFeatures ;
this.imageSource = ('') ;
if (this.cardnumber) {
if (this.cardnumber.startsWith('4')) {
return cardTypeType.Visa;
} else if (this.cardnumber.startsWith('5')) {
return cardType.MasterCard;
} else if (this.cardnumber.startsWith ('60')) {
return cardType.Discover;
}
}
return cardType.Unknown ;
NGOnChangesFeatures;
this.imageSource = 'assets/card-types/' +
this.getCardTypeFromNumber () + '.png' ;
Please fix this code to get the output - attribute directives to display credit card logo based on the credit card number- in Angular
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started