首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带布线的Angular 7多参数

带布线的Angular 7多参数
EN

Stack Overflow用户
提问于 2019-07-04 21:49:03
回答 1查看 56关注 0票数 0

我正在尝试使用不同的参数导航到相同的组件。我可以通过激活路径订阅params,但无法从订阅中调用params内的router.navigate

sidemenu.component.ts

代码语言:javascript
复制
  getTestValue(value:String){
  this._router.navigate(['/example/home',value]);
 }  

home.component.ts

代码语言:javascript
复制
 ngOnInit() {
  this.route.params.subscribe(params => {
  let id = params['id']; // (+) converts string 'id' to a number
  console.log("params value"+id)// I am able to get this value but it is 
   nout ipdating component

   this._router.navigate(['/example/home',id]); // This is not getting called
   }

我知道我们可以选择使用this,但我不想使用this作为this启动另一个组件的ngOnInit钩子。

代码语言:javascript
复制
   this._router.routeReuseStrategy.shouldReuseRoute = function() {
    return false;
   };

https://localhost:4200/example/home/123

https://localhost:4200/example/home/456 //这不是组件未更新

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-04 22:36:43

这很简单。只需使用对象将参数映射到key-value即可。

代码语言:javascript
复制
this._router.navigate(['/example/home', { id: id }])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56889396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档