javascript - How is browser's debugger different from Angular's setTimeout()?
问题描述
I am working on an angular app which is embedded in an application I don't have access to. I am using a router to move from page to page once a pop-up modal has been OK'd (checkbox & button). I have to ensure that the modal has been destroyed before moving to the next page or the outer page causes problems. I have tried using *ngif="destroyModal"
. It works, but it's not happening in-time.
When I set the browser's debugger to stop the action on line with this.myRequestService.update...
it seems to stop the action in such a way that my modal destroy works. If I use a debugger break-point on the next line (in the called-method) it doesn't work.
public goToPageTwo(): void {
this.myObject = {};
this.myRequestService.updateNextPg(this.myObject).subscribe((nextPageResponse) => {
this.nextPageService.setData(nextPageResponse);
this.router.navigateByUrl(NEXT_PAGE);
}
}
I have tried several approaches with setTimeout(() => this.router.navigateByUrl(NEXT_PAGE), 2000)
but this doesn't seem to have any effect. The only stop that allows the modal destroy to happen is one delivered by a debugger break-point.
I can't ask the user to do this :(
解决方案
您应该在ngOnDestroy()生命周期事件中使用页面导航。
myClass {
...
ngOnDestroy(){
//do it here
}
}
当组件关闭和清理时,这将是您想要引起页面导航的地方。
推荐阅读
- node.js - 如何在nodejs中重用不同SFTP传输之间的SSH连接
- python - 如何在主函数中打印一个值?
- docker - Pycharm docker run 配置不接受环境变量
- wonderware - Wonderware 信息服务器过程图形
- php - 使用 PHP 和 SQL 检索数据时遇到问题
- google-oauth - 如何在不使用库的情况下获取 GDrive 访问令牌?
- angularjs - 将我的 json 文件中的数据放入 ui-bootstrap 轮播
- apache-spark - 使用 (py)Spark 设置 Hive TBLPROPERTIES
- xcode - Xcode 10 模拟器运行时不可用:找不到运行时配置文件错误
- matlab - 如何计算两个矩阵的外积平方和减去Matlab中的公共矩阵?