S
S
slowkazak2017-05-12 16:03:11
Angular
slowkazak, 2017-05-12 16:03:11

How to dynamically create a template in Angular 2 4.x?

Please, gentlemen, give a hint.
There is a DOM structure that is dynamically generated, for example this . I want to place this house structure in a component so that instructions like {{1+1}} and, in general, any instructions of the template engine are correctly processed. Who can tell how to do it? '<p>{{1+1}}</p>'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2017-05-12
@lorus

You can try with NgComponentOutlet
Something like this:

@Component({
  template: `<ng-container *ngComponentOutlet="myComponent"></ng-container>`
})
export class MyContainerComponent {

  @Input()
  myTemplate: string;

  get myComponent(): Type<any> {

    const template = this.myTemplate;

    @Component({template})
    class MyComponent {
    };

    return MyComponent;
  }
}

Most likely will not work with AOT.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question