作者:ChrisBao | 来源:互联网 | 2023-02-04 20:46
假设我们有一个TopComponent
使用这样的模板调用的组件:
它的代码很简单:
//... imports ...
@Component({
// selector, styles etc
})
export class TopComponent implements AfterViewInit {
@ViewChild('top') topComp : NgbModal;
// NgbModal is a type provided by some 3rd-party library
// I can't modify it
ngAfterViewInit() {
// let's access the #inner component from here
}
}
我可以#top
使用以下代码访问组件:
@ViewChild('top') topComponent: TopComponent;
如何#inner
从同一个类访问组件?
我尝试过@ContentChild('inner')
但仍在使用undefined
.
PS.我知道我可以创建另一个组件,使用它而不是
从中访问所有必需的子组件.但这可以以某种方式避免吗?