Skip to content

Commit

Permalink
fix(module:date-picker): fix select error when ngmodel set to null (#310
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nuonuoge authored and Guoyuanqiang committed Feb 28, 2019
1 parent 98bd525 commit 58e88ca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions components/date-picker/date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ describe('DatePickerComponent', () => {
dispatchTouchEvent(target, 'mouseup', 0, 0);
fixture.detectChanges();
});

it('should ngmodel default value work', () => {
component.value1 = null;
component.name1 = null;
fixture.detectChanges();
button.click();
fixture.detectChanges();
datePickerEle = document.querySelector('datepicker');
datePickerEle.querySelector('.am-picker-popup-header-right').click();
fixture.detectChanges();
expect(component.value1.getTime()).not.toBeNaN();
});
});

@Component({
Expand Down
6 changes: 4 additions & 2 deletions components/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class DatePickerComponent implements OnInit, OnDestroy, AfterViewInit {
}

transformDateFormat(date): any {
if (!date || date === '') {
if (!date) {
return '';
} else {
return 'yyyy-mm-dd-HH-MM'
Expand Down Expand Up @@ -730,10 +730,12 @@ export class DatePickerComponent implements OnInit, OnDestroy, AfterViewInit {
ngOnInit() {
this.checkMode(this.options.mode);
const value = this.transformDateFormat(this.options.value).split('-');
if (value.length > 0) {
if (value.length > 1) {
this.current_time = this.currentTime = value.map(item => {
return parseInt(item, 0);
});
} else {
this.currentTime = this.current_time;
}
this.localeProvider();
}
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Used to select a date or time.
Properties | Descrition | Type | Default
-----------|------------|------|--------
| mode | mode value, can be a `date` or `time` or `datetime` or `year` or `month` | String | `date` |
| ngModel | the currently selected value | Date | - |
| ngModel | the currently selected value | Date | current time |
| minDate | minimum date | Date | 2000-1-1 |
| maxDate | maximum date | Date | 2030-1-1 |
| minuteStep | The amount of time, in minutes, between each minute item. | Number | 1 |
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ subtitle: 日期选择
属性 | 说明 | 类型 | 默认值
----|-----|------|------
| mode | 日期选择的类型, 可以是日期`date`,时间`time`,日期+时间`datetime`,年`year`,月`month` | String | `date` |
| ngModel | 当前选中时间 | Date | |
| ngModel | 当前选中时间 | Date | 当前时间 |
| minDate | 最小可选日期 | Date | 2000-1-1 |
| maxDate | 最大可选日期 | Date | 2030-1-1 |
| minuteStep | 分钟数递增步长设置 | Number | 1 |
Expand Down

1 comment on commit 58e88ca

@Guoyuanqiang
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close #308

Please sign in to comment.