1
Angular2 rc.4 - rc.5angular2以编程方式从资源文件导入组件
我们可以通过编程方式导入组件吗?
例如,如果我有以下import语句我想转换
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
是它可以导入使用system.import从资源文件如下运行时组件?任何建议表示赞赏
我有一个数组 让利路线: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);
我们怎样才能做到这一点在app.routing角度最终版本。?你能否提供一些更多的信息或分享样本,这有助于更好地学习。 – Karthick