Angular 2 - how to pass data to a child component without rendering the child component twice?

后端 未结 1 1788
猫巷女王i
猫巷女王i 2021-01-24 03:16

I want to pass an object from app.component to a child component (home.component). Am I using routing the wrong way and that\'s why the child component I want to pass the object

相关标签:
1条回答
  • 2021-01-24 03:56

    That's a known issue

    • https://github.com/angular/angular/issues/4452

    Binding currently just doesn't work with components added dynamically. But you can pass data imperatively like:

    app.component.html

    <router-outlet (activate)="activated($event)"></router-outlet>
    

    app.component.ts

    activated(comp: any) {
      if(comp instanceof HomeComponent) {
        comp.testdata = this.testdata;
      }
    }
    

    Plunker Example

    This also might be related

    • How to inject data into Angular2 component created from a router?
    0 讨论(0)
提交回复
热议问题