2017-04-06 111 views
0

我使用datepicker从这里https://github.com/kekeh/mydatepicker/blob/master/README.md,我需要禁用日期,直到今天,所以我需要得到当天的月份和年份,并通过它myDatePickerOptions我用新的日期()函数来获取我的日期得到这样的(星期四2017年4月6日15时55分09秒GMT + 0530(印度标准时间),所以不能使用它myDatepickerOptions怎样才能一天月份和年份?我曾尝试下面的代码。如何在datepicker中禁用今天直到今天?

import { Component, OnInit,ViewEncapsulation } from '@angular/core'; 
import { HeaderComponent } from '../header/header.component'; 
import {IMyOptions, IMyDateModel,IMyDate} from 'mydatepicker'; 
import { TimepickerConfig } from 'ng2-bootstrap/timepicker'; 
import { FormGroup,FormControl,Validators } from '@angular/forms'; 

@Component({ 
    selector: 'app-createsession', 
    templateUrl: './createsession.component.html', 
    styleUrls: ['./createsession.component.css'], 
    encapsulation: ViewEncapsulation.None 
}) 
export class CreatesessionComponent implements OnInit { 

    eventform : FormGroup ; 

    public mytime: Date = new Date(); 

    private myDatePickerOptions: IMyOptions = { 
     // need use the current day,month and year 

     disableUntil: {year: 2016, month: 8, day: 10}, 
     dateFormat: 'dd.mm.yyyy' 
    }; 
    constructor() { } 

    ngOnInit() { 
    console.log(this.mytime); 

    }); 

    } 
    onDateChanged(event: IMyDateModel) { 
     // event properties are: event.date, event.jsdate, event.formatted and event.epoc 
    } 




onSubmit(){ 
    console.log(this.eventform.value); 
} 
} 

回答

1

从当前日期提取日期,年份和月份,并将其设置为disableUntil属性。

public mytime: Date = new Date(); 

currentYear: any = this.mytime.getUTCFullYear(); 
currentDate: any = this.mytime.getUTCDate(); 
currentMonth: any = this.mytime.getUTCMonth() + 1; //months from 1-12 

private myDatePickerOptions: IMyOptions = { 
    // need use the current day,month and year 

    disableUntil: {year: this.currentYear, month: this.currentMonth, day: this.currentDate}, 
    dateFormat: 'dd.mm.yyyy' 
}; 
+0

where应该我在ngOnInit()方法中设置currentyear,currentdate和month? –

+0

你可以把它放在mytime下面。请找到我更新的答案。 – Vikash