Skip to content

Commit 4b8d6ee

Browse files
committed
creditcard: year model binding issue resloved
1 parent b3f6997 commit 4b8d6ee

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/models/creditcardmodel.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ export class AmexioCreditCardModel {
99
this.cvv = null;
1010
this.cardnumber = null;
1111
this.expMonth = 1;
12-
this.expYear = 2018;
13-
}
12+
this.expYear = new Date().getFullYear(); }
1413
}

src/module/forms/creditcard/creditcard.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</select>
2929
</div>
3030
<div class="dateSglCol">
31-
<select [(ngModel)]="creditCardModel.expYear" yearControl="yearControl" style="padding:10px" placeholder="YY">
31+
<select [(ngModel)]="creditCardModel.expYear" (ngModelChange)="onChangeYear($event)" yearControl="yearControl" style="padding:10px" placeholder="YY">
3232
<option *ngFor="let year of yearList">{{year}}</option>
3333
</select>
3434
</div>
@@ -68,7 +68,7 @@
6868
</select>
6969
</div>
7070
<div class="date">
71-
<select [(ngModel)]="creditCardModel.expYear" yearControl="yearControl" style="padding:10px" placeholder="YY">
71+
<select [(ngModel)]="creditCardModel.expYear" (ngModelChange)="onChangeYear($event)" yearControl="yearControl" style="padding:10px" placeholder="YY">
7272
<option *ngFor="let year of yearList">{{year}}</option>
7373
</select>
7474
</div>

src/module/forms/creditcard/creditcard.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export class AmexioCreditcardComponent implements ControlValueAccessor, OnInit {
101101
this.creditCardModel = modelValue;
102102
this.onChangeCardNumber(this.creditCardModel.cardnumber);
103103
this.onChangeMonth('0' + this.creditCardModel.expMonth);
104+
this.onChangeYear(this.creditCardModel.expYear);
104105
this.isCvvValid = this.cvvRegex.test(this.creditCardModel.cvv);
105106
this.cardRegexMap.forEach((value: any, key: string) => {
106107
const isEagarValid = value.test(this.dummyCreditCardNumber);
@@ -201,6 +202,7 @@ export class AmexioCreditcardComponent implements ControlValueAccessor, OnInit {
201202
}
202203
// Map Implementation for key value pair
203204
ngOnInit() {
205+
this.creditCardModel = new AmexioCreditCardModel();
204206
this.cardRegexMap = new Map();
205207
this.cardPatternMap = new Map();
206208
this.cardRegexMap.set('eagerflagvisa', this.visaEagerReg);
@@ -336,4 +338,7 @@ export class AmexioCreditcardComponent implements ControlValueAccessor, OnInit {
336338
this.dummyMonth = event;
337339
this.creditCardModel.expMonth = +this.dummyMonth;
338340
}
341+
onChangeYear(event: any) {
342+
this.creditCardModel.expYear = event;
343+
}
339344
}

0 commit comments

Comments
 (0)