我们如何在HTML中访问组件模块?

时间:2017-05-23 06:36:34

标签: node.js angular webpack-2 typescript2.2

我们可以使用其选择器在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'.

0 个答案:

没有答案