填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

ANALYZE_FOR_ENTRY_COMPONENTS

A DI token that you can use to create a virtual provider that will populate the entryComponents field of components and NgModules based on its useValue property value. All components that are referenced in the useValue value (either directly or in a nested array or map) are added to the entryComponents property.

      
      const ANALYZE_FOR_ENTRY_COMPONENTS: InjectionToken<any>;
    

使用说明

The following example shows how the router can populate the entryComponents field of an NgModule based on a router configuration that refers to components.

// helper function inside the router function provideRoutes(routes) { return [ {provide: ROUTES, useValue: routes}, {provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: routes, multi: true} ]; } // user code let routes = [ {path: '/root', component: RootComp}, {path: '/teams', component: TeamsComp} ]; @NgModule({ providers: [provideRoutes(routes)] }) class ModuleWithRoutes {}
      
      
  1. // helper function inside the router
  2. function provideRoutes(routes) {
  3. return [
  4. {provide: ROUTES, useValue: routes},
  5. {provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: routes, multi: true}
  6. ];
  7. }
  8.  
  9. // user code
  10. let routes = [
  11. {path: '/root', component: RootComp},
  12. {path: '/teams', component: TeamsComp}
  13. ];
  14.  
  15. @NgModule({
  16. providers: [provideRoutes(routes)]
  17. })
  18. class ModuleWithRoutes {}