【发布时间】:2020-01-30 22:58:04
【问题描述】:
我想在刷新页面后显示相同的搜索结果。例如,我通过 get 请求提供年、周、页、分支 (2017,17,01, R) 参数来搜索一个传单。当我刷新页面时,我来到了 ngOnInIt 中的参数。
我想根据我的搜索参数显示最新结果,而不是 ngOnInIt() 中的内容。下面是我的组件。
ngOnInit() {
if (this.showRaster === true) {
this.jahr = this.year;
this.woche = this.week;
this.seite = this.page;
this.filiale = this.branch;
this.flyerhammService.getFlyer(this.branch, this.year, this.woche, this.seite)
.then(
flyers => {
this.flyers = flyers;
this.raster = this.flyers[0].Raster;
}
).catch(
error => console.log(error)
);
} else {
// Below code is to get a flyer with current values of week and year and seite will always be 01
this.jahr = (new Date()).getFullYear();
this.currentWeek = String((this.currentWeekNumber()));
if (this.currentWeek.length < 2) {
this.woche = '0' + this.currentWeek;
} else {
this.woche = this.currentWeek;
}
this.seite = '01';
this.filiale = 'H';
this.flyerhammService.getFlyer(this.filiale, this.jahr, this.woche, this.seite)
.then(
flyers => {
this.flyers = flyers;
this.raster = this.flyers[0].Raster;
}
).catch(
error => console.log(error)
);
}
}
我正在尝试使用 afterViewInit 来完成,但无法得到我想要的。有人可以告诉我我做错了什么吗?即使在刷新页面后如何显示相同的结果?
【问题讨论】: