Angular2: replace host element with component's template

前端 未结 5 1709
别跟我提以往
别跟我提以往 2021-01-30 17:23

I\'m new to angular in general and to angular2 specifically. I\'m trying to write a container component, which should have child components in it.

5条回答
  •  野的像风
    2021-01-30 17:52

    New angular versions have really cool directive, which may be used also for your use case. Tadaa: NgComponentOutlet. Happy coding ;)

    Example:

    @Component({selector: 'hello-world', template: 'Hello World!'})
    class HelloWorld {
    }
    
    @Component({
      selector: 'ng-component-outlet-simple-example',
      template: ``
    })
    class NgTemplateOutletSimpleExample {
      // This field is necessary to expose HelloWorld to the template.
      HelloWorld = HelloWorld;
    }
    

提交回复
热议问题