I have 2 @components say and . Now, I have to load dynamically as innerHTML in say for e.g. as below
component-1.html
<div [innerHTML]="domEl | safeHtml"></div>
In the Angular2 component-1 class
import {
Component,
OnInit,
ViewEncapsulation
} from '@angular/core';
@Component({
selector: 'component-1',
templateUrl: './component-1.html',
encapsulation: ViewEncapsulation.None
})
export class Component1 implements OnInit {
public ngOnInit() {
this.domEl = '<component-2 data="1234"></component-2>'
}
}
component-2 is already inject in app.module.ts file via declarations[]. Also safeHtml is the pipes used for safe HTML transformation.
Even then the problem is component-2 is not loading. Can anyone suggest how I can fix this?
Note:
- if I include component-2 in component-1.html directly it will work. But we have a case where we cannot inject component-2 dynamically.
- Stack is build on Angular2, TypeScript and Webpack.