How to create higher order components in Angular 2

angular

Solution

Use NgComponentOutlet

Simple case

@Component({selector: 'hello-world', template: 'Hello World!'})
class HelloWorld {
}

@Component({
  selector: 'ng-component-outlet-simple-example',
  template: `<ng-container *ngComponentOutlet="myComponent"></ng-container>`
})
class NgTemplateOutletSimpleExample {
  // This field is necessary to expose HelloWorld to the template.
  myComponent= HelloWorld;
}

Advanced cases including providing Injector and Content are available in official documentation

Problem

Higher Order Components (HOC) is a pattern common among React community. See this article if you don't know what's a HOC Do they make sense in Angular 2? How to make a HOC? Any examples?

Original source