如何编译由字符串定义的组件并将其呈现在我的模板中?
我尝试使用DomSanitizer
:
this.sanitizer.bypassSecurityTrustHtml(parsedLinksString);
但这并没有正确绑定click
事件处理程序onButtonClick()
。
所需的功能
@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');
}
}