How do I compile a component defined by a string and render it in my template?
I tried using DomSanitizer
:
this.sanitizer.bypassSecurityTrustHtml(parsedLinksString);
But that doesn't properly bind the click
event handler onButtonClick()
.
Desired Functionality
@Component({
selector: 'app-sample-component',
templateUrl: './sample-component.component.html',
styleUrls: ['./sample-component.component.scss']
})
export class SampleComponent {
buildMessage() {
// How do I parse this string and render so that it responds to events?
const myOutput = '<button (click)="onButtonClick()';
}
onButtonClick() {
console.log('Handler for Dynamic Button');
}
}