I am developing an application using Ionic 3 and I have a problem using DateTime . Suppose I have a DateTime component in the user interface and it is optional, so the default value is optional. There is no minimum date, and the maximum date is 2 years from the current date:
<ion-datetime displayFormat="DD/MM/YYYY" [(ngModel)]="dataInicial" doneText="Feito"
cancelText="Cancelar" [max]="maxDate">
</ion-datetime>
export class AbaPedidosConfirmadosPage {
dataInicial:Date;
maxDate:string;
constructor() {
this.maxDate = moment().add(2, 'years').format('YYYY');
}
}
So, the question is: is there a way by which the collector is selected with the current date selected with the model undefined (or null)? This is for ease of use, in this case, if the user needs to select a date tomorrow, he will need to change the year, then the month and, finally, the day; if it loads the picker contents on the current date, the user needs to change the day.
, , DateTime :
@Directive({
selector: '[load-date]'
})
export class LoadDateDirective {
private lastValue:any;
@Input() public ngModel:any;
@Output('ngModelChange') modelChange:EventEmitter<string> = new EventEmitter<string>();
public constructor(private _elementRef:ElementRef,
private _renderer:Renderer) {
}
@HostListener('click', ['$event'])
_click(ev: UIEvent) {
this.lastValue=this.ngModel;
if(!this.lastValue) {
ev.preventDefault();
ev.stopPropagation();
this.modelChange.next(moment().format('YYYY-MM-DD'));
}
}
}
. , , :

, , , , :

, , , .