如何在页面刷新或angular4页面更改时设置日期时间选择器的日期
How to set the date of the date-time picker on page refresh or page change in angular4
我正在使用来自 -
的 ng2-date 时间选择器
https://www.npmjs.com/package/angular2-datetimepicker
假设我转到位于第 1 页内的第 2 页,而您只有在通过按日期搜索日期时间选择器搜索数据后才能获得第 2 页。然后我在 page-2 并取消 page-2 并返回 page-1 ,日期时间选择器重置。我试图再次返回相同的日期但无济于事(可能是我的代码实现不正确)。一旦页面 changes.And 是否有办法返回相同的日期时间选择器是否会自行重置页面刷新后的日期或代码中的日期变量也被重置。
所以我的问题是 - 如何将其值设置为与之前页面相同的值 change/refresh。
我尝试使用 [options] 但无济于事 -
代码-
transaction.component.html
<div class="form-group " >
<angular2-date-picker
[options]="toDateTransaction"
title="Click to enter To Date and Time"
[(ngModel)]="date1" [settings]="settings1"
[(ngModel)]="toDateTransaction"
formControlName="toDateTransaction"></angular2-date-picker>
</div>
transaction.component.ts
export class TransactionComponent implements OnInit{
date1: Date = new Date();
settings1 = {
bigBanner: true,
timePicker: true,
format: 'yyyy-MM-dd hh:mm',
defaultOpen: false
}
ngOnInit() {
this.toDateTransaction = this.shareData.toDateTransact;
}
searchByDate(data_fromDate, data_toDate,filterDataForSearch) {
this.shareData.toDateTransact = this.dataToDate;
this.toDateTransaction = this.shareData.toDateTransact;
}
}
错误 -
Uncaught (in promise): Error: Template parse errors:
Can't bind to 'options' since it isn't a known property of 'angular2-
date-picker'.
<angular2-date-picker title="Click to enter From Date and Time"
[ERROR ->][options]="fromDateTransaction"
[(ngModel)]="date" [settings]="settings"
"): ng:///MasterSystemModule/TransactionComponent.html@52:84
里面没有options
property
date picker documentation,
所以用,
<angular2-date-picker title="Click to enter To Date and Time" [settings]="settings1" [(ngModel)]="toDateTransaction">
</angular2-date-picker>
现在,要在刷新时获取数据,请将数据存储在 Localstorage
中
ngOnInit() {
if(localStorage.getItem('date'))
{
this.toDateTransaction = JSON.parse(localStorage.getItem('date'));
}
}
searchByDate(data_fromDate, data_toDate,filterDataForSearch) {
this.shareData.toDateTransact = this.dataToDate;
this.toDateTransaction = this.shareData.toDateTransact;
localStorage.setItem('date', JSON.stringify(this.toDateTransaction))
}
我正在使用来自 -
的 ng2-date 时间选择器https://www.npmjs.com/package/angular2-datetimepicker
假设我转到位于第 1 页内的第 2 页,而您只有在通过按日期搜索日期时间选择器搜索数据后才能获得第 2 页。然后我在 page-2 并取消 page-2 并返回 page-1 ,日期时间选择器重置。我试图再次返回相同的日期但无济于事(可能是我的代码实现不正确)。一旦页面 changes.And 是否有办法返回相同的日期时间选择器是否会自行重置页面刷新后的日期或代码中的日期变量也被重置。
所以我的问题是 - 如何将其值设置为与之前页面相同的值 change/refresh。
我尝试使用 [options] 但无济于事 -
代码-
transaction.component.html
<div class="form-group " >
<angular2-date-picker
[options]="toDateTransaction"
title="Click to enter To Date and Time"
[(ngModel)]="date1" [settings]="settings1"
[(ngModel)]="toDateTransaction"
formControlName="toDateTransaction"></angular2-date-picker>
</div>
transaction.component.ts
export class TransactionComponent implements OnInit{
date1: Date = new Date();
settings1 = {
bigBanner: true,
timePicker: true,
format: 'yyyy-MM-dd hh:mm',
defaultOpen: false
}
ngOnInit() {
this.toDateTransaction = this.shareData.toDateTransact;
}
searchByDate(data_fromDate, data_toDate,filterDataForSearch) {
this.shareData.toDateTransact = this.dataToDate;
this.toDateTransaction = this.shareData.toDateTransact;
}
}
错误 -
Uncaught (in promise): Error: Template parse errors:
Can't bind to 'options' since it isn't a known property of 'angular2-
date-picker'.
<angular2-date-picker title="Click to enter From Date and Time"
[ERROR ->][options]="fromDateTransaction"
[(ngModel)]="date" [settings]="settings"
"): ng:///MasterSystemModule/TransactionComponent.html@52:84
里面没有options
property
date picker documentation,
所以用,
<angular2-date-picker title="Click to enter To Date and Time" [settings]="settings1" [(ngModel)]="toDateTransaction">
</angular2-date-picker>
现在,要在刷新时获取数据,请将数据存储在 Localstorage
ngOnInit() {
if(localStorage.getItem('date'))
{
this.toDateTransaction = JSON.parse(localStorage.getItem('date'));
}
}
searchByDate(data_fromDate, data_toDate,filterDataForSearch) {
this.shareData.toDateTransact = this.dataToDate;
this.toDateTransaction = this.shareData.toDateTransact;
localStorage.setItem('date', JSON.stringify(this.toDateTransaction))
}