Skip to content

Commit

Permalink
feat(range): add event on click to range so we can get the label and …
Browse files Browse the repository at this point in the history
…the dates of the clicked range

#20
  • Loading branch information
fetrarij committed Jul 11, 2018
1 parent 94be47d commit 72d43b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -130,4 +130,10 @@ ranges: any = {
}
```

## Available events

### \(rangeClicked)

>Fired when clicked on range, and send an object with range label and dates value, eg: `{label: 'This Month', dates: [Moment, Moment]}`
## [License](https://github.com/fetrarij/ngx-daterangepicker-material/blob/master/LICENSE)
1 change: 1 addition & 0 deletions demo/src/app/custom-ranges/custom-ranges.component.html
Expand Up @@ -12,6 +12,7 @@
[maxDate]="maxDate"
[minDate]="minDate"
[linkedCalendars]="true"
(rangeClicked)="rangeClicked($event)"
class="form-control"
placeholder="Select please..."/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions demo/src/app/custom-ranges/custom-ranges.component.ts
Expand Up @@ -31,6 +31,9 @@ export class CustomRangesComponent implements OnInit {
this.minDate = moment().subtract(3, 'days');
this.alwaysShowCalendars = true;
}
rangeClicked(range) {
console.log('range is : ', range);
}

ngOnInit() {}
}
9 changes: 6 additions & 3 deletions src/daterangepicker/daterangepicker.component.ts
Expand Up @@ -65,11 +65,13 @@ export class DaterangepickerComponent implements OnInit {

options: any = {} ; // should get some opt from user
@Output('choosedDate') choosedDate:EventEmitter<Object>;
@Output('rangeClicked') rangeClicked:EventEmitter<Object>;

constructor(
private el: ElementRef
) {
this.choosedDate = new EventEmitter();
this.rangeClicked = new EventEmitter();
this.updateMonthsInView();
}

Expand Down Expand Up @@ -652,6 +654,7 @@ export class DaterangepickerComponent implements OnInit {
if (!this.alwaysShowCalendars) {
this.isShown = false; // hide calendars
}
this.rangeClicked.emit({label: label, dates: dates});
this.clickApply();
}
};
Expand Down Expand Up @@ -695,7 +698,7 @@ export class DaterangepickerComponent implements OnInit {
* @param e event
*/
handleInternalClick(e) {
e.stopPropagation( )
e.stopPropagation()
}
/**
* update the locale options
Expand Down Expand Up @@ -723,7 +726,7 @@ export class DaterangepickerComponent implements OnInit {
* fit into minDate and maxDate limitations.
*/
disableRange(range) {
if(range === this.locale.customRangeLabel){
if (range === this.locale.customRangeLabel) {
return false;
}
const rangeMarkers = this.ranges[range];
Expand All @@ -735,6 +738,6 @@ export class DaterangepickerComponent implements OnInit {
return date.isAfter(this.maxDate)
});

return(areBothBefore || areBothAfter);
return (areBothBefore || areBothAfter);
}
}
4 changes: 4 additions & 0 deletions src/daterangepicker/daterangepicker.directive.ts
Expand Up @@ -126,7 +126,11 @@ export class DaterangepickerDirective implements OnInit, OnChanges, DoCheck {
this._changeDetectorRef.markForCheck();
}
@Output('change') onChange: EventEmitter<Object> = new EventEmitter();
@Output('rangeClicked') rangeClicked: EventEmitter<Object> = new EventEmitter();
ngOnInit() {
this.picker.rangeClicked.asObservable().subscribe((range: any) => {
this.rangeClicked.emit(range);
});
this.picker.choosedDate.asObservable().subscribe((change: any) => {
if (change) {
const value = {};
Expand Down

0 comments on commit 72d43b6

Please sign in to comment.