如何以angular2重新加载页面。
在通过网络搜索时,我得到了一个代码"this._router.renavigate()"
来重新加载页面,但看起来它不适用于最新版本的angular2。
另一种方式是'window.location.reload()'
,但这不是做角度的方式。
答案 0 :(得分:14)
如果您真的想重新加载页面,则需要在角度区域外运行location.reload()
this.zone.runOutsideAngular(() => {
location.reload();
});
用RC6测试
完整示例
import { Component, NgZone } from "@angular/core";
@Component({
templateUrl: "template.html"
})
export class ReloadComponent{
constructor(
private zone: NgZone) {
}
reloadPage() { // click handler or similar
this.zone.runOutsideAngular(() => {
location.reload();
});
}
}
答案 1 :(得分:2)
对于partial,有办法编写自己的函数
public renavigate(): void {
let params: Object = {};
Object.assign(params, this.routeParams.params);
params['ref'] = (params['ref'] === ref) ? ref + new Date().getTime() : ref;
this.router.navigate(['Foo', params]);
}
答案 2 :(得分:1)
这对我有用:
#include <iostream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <thread>
int main()
{
std::wstring updateTime(L"Thu Dec 14 15:06:00 2016");
std::wstring updatePeriod(L"30");
std::string timeUpdate(updateTime.begin(), updateTime.end());
std::istringstream ss{ timeUpdate };
struct tm dateUp ={};
ss >> std::get_time(&dateUp, "%a %b %d %X %Y");
std::time_t t1 = std::mktime(&dateUp);
//time_t t1 = std::mktime(&dateUp); // Contine data la care se porneste testul
int periodUpdate = std::stoi(updatePeriod); // Contine numarul de minute
std::cout <<"Data inainte de a se adauga minutele = "<< 1900 + dateUp.tm_year << " " << dateUp.tm_mon << " " << dateUp.tm_mday << " " << dateUp.tm_hour << ":" << dateUp.tm_min << "\n\n";
// Adaug minutele la data la care se porneste testul si apoi refac structura de tip time_t (minutele se convertesc automat in ore, zile..)
dateUp.tm_min += periodUpdate;
t1 = std::mktime(&dateUp);
std::cout <<"Data dupa ce s-au adaugat minutele = "<< 1900 + dateUp.tm_year << " " << dateUp.tm_mon << " " << dateUp.tm_mday << " " << dateUp.tm_hour << ":" << dateUp.tm_min << "\n\n";
// Retin data curenta a calculatorului
time_t now = time(NULL);
struct tm now_tm = *localtime(&now);
time_t t2 = std::mktime(&now_tm);
std::cout << "Data curenta = "<<1900 + now_tm.tm_year << " " << now_tm.tm_mon << " " << now_tm.tm_mday << " " << now_tm.tm_hour << ":" << now_tm.tm_min << "\n\n";
//Compar cele 2 date. Pentru a se face update programat diferenta trebuie sa fie pozitiva. Adica data actuala sa fie mai mare decat data la care ar trebui sa se faca update
double diff = difftime(t2, t1);
std::cout << diff << "\n";
}
答案 3 :(得分:1)
我遇到了同样的问题,这对我有用:
import { Location } from '@angular/common';
constructor(private location: Location) {}
ngOnInit() { this.load(); }
load() {
this.location.reload();
}
&#13;
答案 4 :(得分:0)
使用
提高知名度的重要性 actions: {
willTransition() {
let records = this.get('controller.records');
records.setEach('selected', false);
}
}
使用户体验更好
答案 5 :(得分:-2)
location.reload()将重新加载页面。