title: Angular router: how to pass data to lazy loading module?
body: <p>I have the following routing paths for a module of my Angular app:</p>
  
  <pre><code>@NgModule({
      imports: [
          RouterModule.forChild([
              {
                  path: 'documents',
                  data: { myObject: MyConstants.OPTION_ONE },
                  children: [
                      {
                          path: ':ID_DOC',
                          children: [
                              { path: 'edit', component: EditDocumentComponent },
                              { path: '', component: DocumentDetailsComponent },
                          ]
                      },
                      { path: 'add', component: AddDocumentComponent },
                      { path: '', component: DocumentsListComponent }
                  ]
              }
          ])
      ],
      exports: [
          RouterModule
      ]
  })
  
  export class DocumentsManagementRoutingModule {
  }
  </code></pre>
  
  <p>As you can see I use <code>data</code> property to pass some data to every path in "documents", so I can get it from any of the Components declared in the routing paths:</p>
  
  <p>For example here is how I get data in <code>DocumentDetailsComponent</code>:</p>
  
  <pre><code>export class DocumentDetailsComponent implements OnDestroy {
      private obsData: Subscription;
      private option: any;
  
      constructor(private route: ActivatedRoute) {
          this.obsData = this.route.data.subscribe(data =&gt; {
              this.option = data['myObject'];
          });
      }
  
      ngOnDestroy(): void {
          this.obsData.unsubscribe();
      }
  }
  </code></pre>
  
  <p>Now I changed the routing structure of the entire app and I call the above module from other modules, in lazy loading, using <code>loadChildren</code> attribute. And I pass data in the same way:</p>
  
  <pre><code>@NgModule({
      imports: [
          RouterModule.forChild([
              {
                  path: 'users',
                  loadChildren: 'app/documents/documents.module#DocumentsModule',
                  data: { myObject: MyConstants.OPTION_ONE }},
              {
                  path: ':ID_USER',
                  children: [
                      { path: 'edit', component: EditUserComponent },
                      { path: '', component: UserDetailsComponent },
                  ]
              },
              { path: 'add', component: AddUserComponent },
              { path: '', component: UserListComponent }
          ])
      ],
      exports: [
          RouterModule
      ]
  })
  
  export class UsersManagementRoutingModule {
  }
  </code></pre>
  
  <p>And I did the same for all the other modules that calls <code>DocumentsManagementRoutingModule</code>, changing <code>myObject</code> property to <code>MyConstants.OPTION_TWO</code>, <code>MyConstants.OPTION_THREE</code> and so on, according to my needs.</p>
  
  <p>Then, since I don't know the module and its related path that calls my lazy loading module, how to get <code>data</code> property from the caller module?</p>