【发布时间】:2018-02-14 18:17:36
【问题描述】:
我在成功删除数据后尝试重定向页面。所以我把重定向 router.navigate 放在数据部分的订阅中。但它不起作用,我也尝试过使用 ngZone 也没有任何反应。我也想显示成功信息。我怎么能证明这一点?
没有 ngZone:
const rid = params['rid'];
this.roleSer.deleteRole(rid).subscribe(
data => { this.router.navigate(['viewroles']) },
error => { error }
);
});
使用 ngZone:
const vrid = this.route.params.subscribe((params: Params) => {
const rid = params['rid'];
this.roleSer.deleteRole(rid).subscribe(
data => { this.zone.run(()=>{
this.router.navigate(['viewroles'])
}); },
error => { error }
);
});
【问题讨论】:
-
this.zone.run(() 是什么?
-
感谢您的建议。我努力了。但不工作
-
你遇到了什么错误?
-
确保你的路径是正确的?