How to dynamically add innerHTML with angular 2 components

Angular doesn’t process HTML added dynamically, it just adds it verbatim except some sanitization to prevent security issues.
See In RC.1 some styles can’t be added using binding syntax for how to prevent the sanitizer of stripping the HTML.

You can use ViewContainerRef.createComponent() like shown in Angular 2 dynamic tabs with user-click chosen components to add components dynamically.

There are also solutions available how to create components dynamically like shown in Equivalent of $compile in Angular 2

Leave a Comment