Angular 2 binding/events not working when adding template as innerHTML

Angular doesn’t process HTML added using innerHtml (also ElementRef.nativeElement.append(...) or similar) in any way.

As mentioned in the comment an alternative is to wrap the HTML in a component and add this component dynamically. DynamicComponentLoader (as shown in the linked answer from the comment to your question) is deprecated. It was replaced by ViewContainerRef.createComponent(). Angular 2 dynamic tabs with user-click chosen components shows an example how to use it.

Leave a Comment