查找ng-content中的所有元素

时间:2017-06-27 17:34:27

标签: angular

鉴于@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的人都必须标记内容待处理。

还有其他方法吗?..

0 个答案:

没有答案