Tworzę aplikację angle2 w RC5, w której chcę dynamicznie ładować komponenty.Alternatywa dla dynamicComponentLoader w angular2 RC5?
w RC1, zrobiłem to samo używając dynamicComponentLoader jak:
@Component({
moduleId: module.id,
selector: 'generic-component',
templateUrl: 'generic.component.html',
styleUrls: ['generic.component.css']
})
export class GenericComponent implements OnInit {
@ViewChild('target',{read:ViewContainerRef}) target;
@Input('component-name') componentName:string;
@Input('component-info') componentInfo:string;
@Input('component-model') componentModel:Object;
keysRegister:string[]=[
'users',
'employee'
];
componentNames:string[]=[
'UserComponent',
'EmpComponent'
];
constructor(private dcl:DynamicComponentLoader) {}
ngOnInit() {
}
ngAfterViewInit(){
let componentIndex=this.keysRegister.indexOf(this.componentName);
this.dcl.loadNextToLocation(StandardLib[this.componentNames[componentIndex]],this.target)
.then(ref=>{
ref.instance.componentModel=this.componentModel;
});
console.log("GenericComponent...... "+this.componentName+" Loaded");
}
}
i gdy chcę załadować składnika zrobiłbym:
<div *ngIf="columnModel" style="border:1px solid orange">
<generic-component
[component-name]="columnModel.componentName" <!-- I will pass *users* here -->
[component-model]="columnModel.componentModel"
[component-info]="columnModel.componentInfo"
></generic-component>
</div>
Próbowałem za pomocą componentResolver ale nie jestem w stanie działa poprawnie. Dowolne wejścia? Dzięki.