在Angular中,当使用CRUD(增删改查)操作后,如果需要刷新页面,可以使用以下解决方法:
import { Router } from '@angular/router';
constructor(private router: Router) { }
refreshPage() {
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.router.navigate([this.router.url]);
});
}
在上述代码中,我们注入了Router服务,并在refreshPage方法中使用navigateByUrl方法重新加载当前页面。skipLocationChange选项用于防止在导航时添加历史记录。
location.reload()方法刷新页面:import { Component } from '@angular/core';
@Component({...})
export class MyComponent {
refreshPage() {
location.reload();
}
}
在上述代码中,我们在组件中定义了refreshPage方法,并使用location.reload()方法刷新页面。
无论使用哪种方法,只需调用refreshPage方法即可在使用CRUD操作后刷新页面。