我们可以使用其选择器在Angular中动态加载组件吗?我需要从HTML
访问组件模块@Component({
moduleId: module.id.toString(),
selector: 'dashboard',
templateUrl: 'dashboard.component.html'
})
export class DashboardComponent implements OnInit {
}
@Component({
moduleId: module.id.toString(),
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['my-component.css']
})
export class MyComponent{
loadComponent = (selector: string, module: any): void => {
this._compiler.compileModuleAndAllComponentsAsync(module).then(_module => {
let _componentFactories = _module.componentFactories.filter(_c => {
// here I am using the selector
return _c.selector === selector.toLocaleLowerCase();
});
});
}
}
HTML
{{loadComponent('dashboard',moduleId)}}
我已关注Load component dynamically in Angular 2 using selector,这会引发以下错误:
No NgModule metadata found for 'undefined'.