Hiển thị các bài đăng có nhãn Datepicker. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Datepicker. Hiển thị tất cả bài đăng

Angular Material Datepicker only MM/YYYY

Source:

<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a month" [formControl]="date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker (monthSelected)="monthSelected($event)" startView="multi-year"></mat-datepicker>
</mat-form-field>


import { Component, ViewChild } from '@angular/core';
import { FormControl } from '@angular/forms';
import { NativeDateAdapter, DateAdapter, MatDatepicker } from '@angular/material';
import * as _moment from 'moment';
import { default as _rollupMoment } from 'moment';

const moment = _rollupMoment || _moment;

class CustomDateAdapter extends NativeDateAdapter {
format(date: Date, displayFormat: Object): string {
var formatString = 'MMMM YYYY';
return moment(date).format(formatString);
}
}

@Component({
selector: 'app-month-picker-example',
templateUrl: './month-picker-example.component.html',
styleUrls: ['./month-picker-example.component.css'],
providers: [
{
provide: DateAdapter, useClass: CustomDateAdapter
}
]
})
export class MonthPickerExampleComponent{
@ViewChild(MatDatepicker) picker;
date = new FormControl();
constructor() { }

monthSelected(params) {
this.date.setValue(params);
this.picker.close();
}

}




/** Copyright 2018 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license */

ngx-bootstrap Datepicker Format Value

Source: https://github.com/valor-software/ngx-bootstrap/issues/868

Two way binding
<input type="text" [bsConfig]="bsConfig" [(ngModel)]="this.pilot.dob"
name="bsDatepicker" class="form-control"
#dp="bsDatepicker" bsDatepicker placeholder="MM-dd-yyyy">
on my submit function I change the format of my model value to MM/dd/yyyy ie 01/01/2018
const date = new Date(this.pilot.dob);
this.pilot.dob = moment(date).format('MM/DD/YYYY');

More about moment at https://momentjs.com/docs/#/displaying/format/

There is no directive with "exportAs" set to "bsDatepicker

Source: https://github.com/valor-software/ngx-bootstrap/issues/2979

in my case i put BsDatepickerModule.forRoot() in global app.module.ts, but then I forgot to import same module inside of child module as well.
And that was my problem too. Maybe it's also yours.

anti-pattern là gì

  Trong công nghệ và lập trình, Anti-pattern (mẫu phản diện) là những giải pháp bề ngoài có vẻ hiệu quả để giải quyết một vấn đề phổ biến, ...