0

仅从相应的页面组件获取 params.get("id"),从其他单个组件(headerComponent)获取参数 id

它是 Angular 7

<app-header></app-header>
<router-outlet></router-outlet>

app.module.ts
app-routing.module.ts (parent route)

common/
   --header.component.ts

projects/
  components-folder
    --component1
    --component2
  --projects.module.ts
  --projects-routing.module.ts (child route)

它正在使用来自对应组件的这些代码,但不适用于 headerComponent

//Its worked only correspond component only 

 this.activatedRoute.paramMap.subscribe( params => {
      this.idname  = params.get("id");
      console.log( this.idname );
    });

如果可能的话,我也可以从其他单独的指令中获取参数吗?

4

0 回答 0