The following example shows how the router can populate the entryComponents
field of an NgModule based on the router configuration which refers to components.
下面的例子说明angular2.0如何基于NgModule配置组件的路由
// 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 {}