最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - set default minute in ngx-mat-datetime-picker in angular? - Stack Overflow

programmeradmin1浏览0评论

HTML:(I have installed ngxMatDatetimePicker for datetime picker.i have set stepminute to every 15 minutes. this will calculate from current minute, but i need set default value should be 00. so if we click up arrow it will add 15,30, 45.. how to set default minute is 00??.. and also input field is taking dd-mm-yyyy hh:mm:ss format, even I gave showseconds to false. actual format should be dd-mm-yyyy hh:mm can you help me?)

   <mat-form-field>
            <input matInput [ngxMatDatetimePicker]="picker" placeholder="Time Slot" formControlName="time_slot"
                [disabled]="disabled">
            <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
            <ngx-mat-datetime-picker #picker [showSpinners]="showSpinners" [showSeconds]="showSeconds"
               [stepHour]="stepHour" [stepMinute]="stepMinute" [stepSecond]="stepSecond"
               [touchUi]="touchUi" [color]="color" [enableMeridian]="enableMeridian" >
            </ngx-mat-datetime-picker>
         </mat-form-field>

ponent.ts:

  public disabled = false;
  public showSpinners = true;
  public showSeconds = false;
  public touchUi = false;
  public enableMeridian = false;
  public stepMinutes = [0o0, 15, 30, 45];
  public stepHour = 1;
  public stepMinute = 15;
  public stepSecond = 1;
  public defaultTime = [new Date().getHours, 0o0 , 0o0] // i have tried like this
  public color: ThemePalette = 'primary';

HTML:(I have installed ngxMatDatetimePicker for datetime picker.i have set stepminute to every 15 minutes. this will calculate from current minute, but i need set default value should be 00. so if we click up arrow it will add 15,30, 45.. how to set default minute is 00??.. and also input field is taking dd-mm-yyyy hh:mm:ss format, even I gave showseconds to false. actual format should be dd-mm-yyyy hh:mm can you help me?)

   <mat-form-field>
            <input matInput [ngxMatDatetimePicker]="picker" placeholder="Time Slot" formControlName="time_slot"
                [disabled]="disabled">
            <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
            <ngx-mat-datetime-picker #picker [showSpinners]="showSpinners" [showSeconds]="showSeconds"
               [stepHour]="stepHour" [stepMinute]="stepMinute" [stepSecond]="stepSecond"
               [touchUi]="touchUi" [color]="color" [enableMeridian]="enableMeridian" >
            </ngx-mat-datetime-picker>
         </mat-form-field>

ponent.ts:

  public disabled = false;
  public showSpinners = true;
  public showSeconds = false;
  public touchUi = false;
  public enableMeridian = false;
  public stepMinutes = [0o0, 15, 30, 45];
  public stepHour = 1;
  public stepMinute = 15;
  public stepSecond = 1;
  public defaultTime = [new Date().getHours, 0o0 , 0o0] // i have tried like this
  public color: ThemePalette = 'primary';

Share Improve this question edited Jun 8, 2020 at 11:50 Rekha asked Jun 8, 2020 at 11:28 RekhaRekha 4237 silver badges25 bronze badges 1
  • hello :) did you find any solution to that ? – toto Commented Aug 19, 2020 at 10:29
Add a ment  | 

1 Answer 1

Reset to default 3

Add defaultTime in the ponent.html

<mat-form-field>
    <input matInput [ngxMatDatetimePicker]="picker" placeholder="Time Slot" formControlName="time_slot"
        [disabled]="disabled">
    <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
    <ngx-mat-datetime-picker #picker [showSpinners]="showSpinners" [showSeconds]="showSeconds"
       [stepHour]="stepHour" [stepMinute]="stepMinute" [stepSecond]="stepSecond"
       [touchUi]="touchUi" [color]="color" [enableMeridian]="enableMeridian" [defaultTime]="defaultTime">
    </ngx-mat-datetime-picker>
</mat-form-field>

In ponent.ts

public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public stepMinutes = [0o0, 15, 30, 45];
public stepHour = 1;
public stepMinute = 15;
public stepSecond = 1;
public defaultTime = [new Date().getHours(), 0 , 0] 
public color: ThemePalette = 'primary';
发布评论

评论列表(0)

  1. 暂无评论