我在项目中使用NG2-数据报警器。这是我正在使用的代码。
<ng2-datepicker class="form-control" required [options]="{format:'MMM DD YYYY'}" [(ngModel)]="User.StartDate" name="StartDate" #StartDate="ngModel"></ng2-datepicker>我被困在
发布于 2017-05-30 13:10:49
在组件中,可以设置格式选项。
在此对示例进行排序:
import { DatePickerOptions, DateModel } from 'ng2-datepicker';
export class Component implements OnInit {
public options: DatePickerOptions;
ngOnInit() {
this.options = {
format: "MM-DD-YYYY",
};
//You should initialize date attribute like
this.user.StartDate = {formatted: 'MM-DD-YYYY'}; // It will work as placeholder/default value;
// If you want blank on init
//this.user.StartDate = {formatted: ''};
}
//before save data
save() {
this.user.StartDate = this.user.StartDate.formatted;
}
//To make it non-editable by a keyboard, but allow Tab and Shift+Tab key
eventHandler(event)
{
if(event.keyCode == 9) {
if(event.shiftKey)
{
return true;
}
return true;
}
else {
return false;
}
}
}在模板文件中:
<ng2-datepicker name="StartDate" [options]="options" [(ngModel)]="user.StartDate" (keydown)="eventHandler($event)"></ng2-datepicker>https://stackoverflow.com/questions/43919503
复制相似问题