2017-08-04 49 views
2

我在启动主题和Angular 2中的p日历有问题,我想在用户选择日期并设置空白值后清除日历值。 我的代码:在primeng pcalendar中设置空白值

组件

<div style="margin-right: -6px"> 
    <p-calendar [(ngModel)]="viewModel.fromDate" [showIcon]="true" readOnlyInputText="true" (click)="restoreValues()"></p-calendar> 
</div> 

打字稿文件

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。 但不工作:(

任何人可以帮助我吗?

在此先感谢。

回答

2

解决!

是不是最好的办法,但工程...

组件

<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(); 

    } 
} 
相关问题