2017-04-06 2 views
0

여기에서 datepicker을 사용하고 있습니다. https://github.com/kekeh/mydatepicker/blob/master/README.md과 오늘까지 날짜를 사용하지 않도록 설정해야합니다. 현재 날짜와 월을 가져와 myDatePickerOptions를 전달해야합니다. 새 Date() 함수를 사용하여 날짜를 가져 왔습니다. 이런 식으로 점점 (목 2017년 4월 6일 15시 55분 9초 (그리니치 표준시) + 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

나는 ngOnInit() 메서드에서 currentyear, currentdate 및 month를 설정합니까 ?? –

+0

mytime 바로 아래에 배치 할 수 있습니다. 제 답변을 찾으십시오. – Vikash