鉴于@ContentChildren('*')
似乎不受支持(at least for the time being),我正在寻找替代方法来基本上访问ng-content
中的所有组件。
基本上我希望我能做一些像:
@Component({selector: 'foo' template: `...`)}
class FooComponent {...}
@Component({selector: 'app' template: `<container><foo></foo></container>`)}
class AppComponent {...}
@Component({selector: 'container', template: `<ng-content>/ng-content>`})
export class Container {
@ContentChildren('*') allComponents; //wish I could get FooComponent here!
}
到目前为止,我提出了解决办法(并在某些情况下被驳回):
1. 有一个基本组件,并找到使用:我不能,因为其中一些组件不是我的,我想避免缠绕第三方。@ContentChildren(Base)
2. 查询本机元素我必须让组件与之交互并设置输入
3.用指令或#id标记内部元素 - 作为最后的手段,我可以做到,但不幸的是,任何使用我的ContainerComponent
的人都必须标记内容待处理。
还有其他方法吗?..