javascript - 如何在 Angular 2 中重新加载组件的内容?

标签 javascript angular components angular2-routing

运行时的某个时刻,我的网址看起来像

http://localhost:4200/personal/51c50594-a95c-4a18-ac7b-b0521d67af96

我想转到一个只有不同 GUID 和不同内容的页面。

http://localhost:4200/personal/{otherGuid}

这是行不通的:

this.router.navigate(['/personal',new_ guid]);

如何在 Angular 2 中实现这一点?

最佳答案

试试下面,

 ....
  this.router.navigate(['personal', id]);
 ....

 constructor(route: ActivatedRoute, router: Router){
  this.route.params.subscribe(param => {
     // this will be fired when you change the guid,
     // use the new param to reload component..
  })
 }

检查这个Plunker !!

关于javascript - 如何在 Angular 2 中重新加载组件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45921198/

相关文章:

javascript - 分配拳击重量级别

javascript/jquery代码组织

angular - 无法使用 WSL 在 Angular 项目中启动 ChromeHeadless,适用于 Mac

angular - RxJS 取消订阅钩子(Hook)

windows - 我怎样才能释放一个 Tpanel 有一个 TbitBtn 调用释放 Tpanel

java - 具有奇怪行为的正则表达式

javascript - 我有一个带有 JQuery 的简单图像图片 slider ,但我不知道如何向上或向下设置动画

javascript - 有没有更干净的方法来消除方法的抖动?

java - Java swing中如何调用self组件?

flash - 是否有像 Flash 那样的预先编写的类似 Silverlight Web 小部件的组件?