如何在angular2中重新加载页面

Kri*_*hna 10 angular2-routing angular

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

kod*_*bot 14

如果你真的想重新加载页面,你需要在角度区域外运行location.reload()

this.zone.runOutsideAngular(() => {
    location.reload();
});
Run Code Online (Sandbox Code Playgroud)

用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();
        });
    }
}
Run Code Online (Sandbox Code Playgroud)


may*_*yur 2

对于部分,可以编写自己的函数

   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]);
   }
Run Code Online (Sandbox Code Playgroud)