gpt4 book ai didi

angular - 如何在angular2中重新加载页面

转载 作者:太空狗 更新时间:2023-10-29 17:06:39 25 4
gpt4 key购买 nike

如何在 angular2 中重新加载页面。
通过网络搜索时,我得到了一个代码 "this._router.renavigate()" 来重新加载页面,但看起来它不适用于最新版本的 angular2。
另一种方式是 'window.location.reload()' 但这不是这样做的 Angular 方式。

最佳答案

如果你真的想重新加载页面,你需要在 Angular 区域外运行 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();
});
}
}

关于angular - 如何在angular2中重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37852968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com