1

I need to create a directive that will generate arbitrary HTML. Directive should generate HTML code is based on external data.

Example:

@Directive({ selector: '[layout]' })
export class Layout {
    constructor(
        private templateRef: TemplateRef,
        private viewContainer: ViewContainerRef){
    }
    @Input() set layout(value) {
        if (value) {
            // Only for example
            var div = document.createElement('div');
            div.innerHTML = '<header>This is {{value}} header</header>';

            // ??? How to put the div element to the View

            var embeddedViewRef  = this.viewContainer.createEmbeddedView(this.templateRef);
        } else {
            this.viewContainer.clear();
        }
    }
}

How to properly create a HTML code for the directive?

AndyGrom
  • 461
  • 1
  • 4
  • 9
  • I found solution in that post http://stackoverflow.com/questions/34784778/equivalent-of-compile-in-angular-2 – AndyGrom Mar 09 '16 at 21:03

0 Answers0