在 angular2 组件中使用嵌入时,我的“ViewChildren”似乎无法检测到这些组件。当我制作一个直接定义相同组件的组件时,它就可以正常工作。现在有人有办法完成这项工作吗?
最佳答案
您可以使用@ContentChild()
或@ContentChildren()
查询嵌入的内容。
@ViewChild()
和 ´@ViewChildren()` 只允许查询组件模板中的元素。
另请参阅angular 2 / typescript : get hold of an element in the template
关于Angular2 ViewChildren 与嵌入相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39190279/