我在启动主题和 Angular 2 中遇到 p-calendar 问题,我想在用户选择日期并设置空白值后清除日历值。 我的代码:
组件
<div style="margin-right: -6px">
<p-calendar [(ngModel)]="viewModel.fromDate" [showIcon]="true" readOnlyInputText="true" (click)="restoreValues()"></p-calendar>
</div>
typescript 文件
export class RequestSearcherComponent implements OnInit {
restoreValues(): void {
this.viewModel.areaIds = [];
this.viewModel.cedingIds = [];
this.viewModel.requestType = [];
this.viewModel.requestResponsible = [];
this.viewModel.requestStatus = [];
this.fromDate.setDate(null);
}
}
作为代码中出现的setDate
,我尝试了很多方法和方式。
但不起作用:(
谁能帮帮我?
提前致谢。
最佳答案
解决了!
这不是最好的方法,但有效...
组件
<div>
<p-calendar #fromCal [(ngModel)]="value" [showIcon]="true" readOnlyInputText="true"></p-calendar>
</div>
typescript 文件
@Component({
selector: 'app-request-searcher',
templateUrl: './request-searcher.component.html'
})
export class RequestSearcherComponent implements OnInit {
@ViewChild('fromCal') calendarFrom: Calendar;
/** My awesome code... */
restoreValues(): void {
this.calendarFrom.value = null;
this.calendarFrom.updateInputfield();
}
}
关于angular - 在 primeng pcalendar 中设置空白值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45502611/