2017-04-06 107 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