我正在做一个Angular项目。我正在努力处理组件中的刷新操作。
我想在单击按钮时刷新路由器的组件。我有刷新按钮,当我点击它时,组件/路由器需要刷新。
我试过了
和
这两个不适合我的需要。如果有人知道这一点,请帮助我。
发布于 2017-12-18 17:03:00
经过一些研究和修改我的代码,如下所示,这个脚本对我起作用了。我只是添加了条件:
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['Your actualComponent']);
});发布于 2018-07-21 13:53:59
使用
this.ngOnInit();
重新加载相同的组件,而不是重新加载整个页面!!
DeleteEmployee(id:number)
{
this.employeeService.deleteEmployee(id)
.subscribe(
(data) =>{
console.log(data);
this.ngOnInit();
}),
err => {
console.log("Error");
}
}发布于 2018-05-01 01:48:28
将此代码添加到所需组件的构造函数中对我很有效。
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
this.mySubscription = this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
// Trick the Router into believing it's last link wasn't previously loaded
this.router.navigated = false;
}
});一定要
从这里
mySubscription
在
..。
ngOnDestroy() {
if (this.mySubscription) {
this.mySubscription.unsubscribe();
}
}有关更多详细信息,请参阅此帖子-
https://github.com/angular/angular/issues/13831
https://stackoverflow.com/questions/47813927
复制相似问题