Angular2 rc.4 - rc.5
Can we import components programmatically ?
for example if i have following import statements i want to convert
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
is it possible to import components on runtime using system.import from the resource file as following ? any suggestion is appreciated
I have an array
let routes: RouterConfig = [];
let routeArr =[
{path: 'hello', component:'HelloComponent', resource:'./hello.component'},
{path:'inc', component:'IncComponent', resource:'./inc.component'}
];
// injecting router object
constructor(private router: Router){
}
// iterating routeArr and creating RouteConfig objects
routeArr.forEach((route : any) => {
// import components programmatically on run time ?
System.import(route.resource).then(
m => {
// create route config object and add in routes object
routes.push({
path: route.path
component: m[route.component]
});
}
)
});
// load all routes which we just created
router.resetConfig(routes);
Surprisingly code in the questions worked :D use the code and enjoy dynamic route addings