@@ -6,7 +6,7 @@ import * as moment from 'moment';
6
6
templateUrl : './month-picker.component.html' ,
7
7
styleUrls : [ './month-picker.component.scss' ]
8
8
} )
9
- export class MonthPickerComponent implements OnInit {
9
+ export class MonthPickerComponent implements OnInit {
10
10
@Output ( ) dateSelected = new EventEmitter < {
11
11
monthIndex : number ;
12
12
year : number ;
@@ -19,38 +19,31 @@ export class MonthPickerComponent implements OnInit {
19
19
20
20
selectedYearText : string ;
21
21
months : Array < string > = [ ] ;
22
- years : Array < number > = [ ] ;
23
22
24
23
constructor ( ) {
25
24
this . selectedYearMoment = moment ( ) ;
26
25
this . selectedMonthMoment = moment ( ) ;
27
26
this . months = moment . months ( ) ;
28
27
this . selectedMonthIndex = this . selectedMonthMoment . month ( ) ;
28
+ this . selectedYearText = moment ( this . selectedYearMoment ) . format ( 'YYYY' ) ;
29
29
this . selectedYear = this . selectedYearMoment . year ( ) ;
30
- this . updateYearText ( ) ;
31
30
}
32
31
33
32
ngOnInit ( ) {
34
33
this . selectDate ( this . selectedMonthIndex , this . selectedYear ) ;
35
34
}
36
35
37
- updateYearText ( ) {
38
- this . selectedYearText = moment ( this . selectedYearMoment ) . format ( 'YYYY' ) ;
39
- }
40
-
41
- increment ( ) {
42
- this . selectedYearMoment = this . selectedYearMoment . add ( 1 , 'year' ) ;
43
- this . updateYearText ( ) ;
44
- }
36
+ changeYear ( changeAction : string ) {
37
+ this . selectedYearMoment [ changeAction ] ( 1 , 'year' ) ;
38
+ this . selectedYear = this . selectedYearMoment . year ( ) ;
45
39
46
- decrement ( ) {
47
- this . selectedYearMoment = this . selectedYearMoment . subtract ( 1 , 'year' ) ;
48
- this . updateYearText ( ) ;
40
+ const monthIndex = changeAction === 'add' ? 0 : 11 ;
41
+ this . selectMonth ( monthIndex ) ;
42
+ this . selectedYearText = moment ( this . selectedYearMoment ) . format ( 'YYYY' ) ;
49
43
}
50
44
51
45
selectMonth ( monthIndex : number ) {
52
46
this . selectedMonthIndex = monthIndex ;
53
- this . selectedYear = this . selectedYearMoment . year ( ) ;
54
47
this . selectDate ( this . selectedMonthIndex , this . selectedYear ) ;
55
48
}
56
49
@@ -65,4 +58,3 @@ export class MonthPickerComponent implements OnInit {
65
58
this . dateSelected . emit ( { monthIndex, year } ) ;
66
59
}
67
60
}
68
-
0 commit comments