How can we access the component module in HTML?

114 views Asked by At

Can we load a component dynamically in Angular using its selector? I need to access component module from 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)}}

I have followed Load component dynamically in Angular 2 using selector, which throws the below error:

No NgModule metadata found for 'undefined'.
0

There are 0 answers