1
Angular2 rc.4 - rc.5angular2 리소스 파일에서 프로그래밍 방식으로 구성 요소 가져 오기
프로그래밍 방식으로 구성 요소를 가져올 수 있습니까? 내가
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
는 다음과 같이 리소스 파일에서 system.import를 사용하여 런타임에 구성 요소를 가져올 수 있습니다을 변환 할 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