高阶组件 (HOC) 是 React 社区中常见的一种模式。参见 this article如果你不知道什么是 HOC
它们在 Angular 2 中有意义吗? 如何制作 HOC? 有例子吗?
最佳答案
简单案例
@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;
}
包括提供 Injector 和 Content 的高级案例在 official documentation 中可用。
关于angular - 如何在 Angular 2 中创建高阶组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40061129/