当 ViewContainerRef
被注入(inject)指令时,它绑定(bind)到什么元素?
例如,如果我们有一个模板:
template `<div><span vcdirective></span></div>`
vcdirective
的构造函数如下所示:
constructor(vc: ViewContainerRef) {
}
vc:ViewContainerRef
是绑定(bind)到span
元素的元素吗?
最佳答案
是的,它将绑定(bind)到 span 元素。如果你在构造函数中控制 vc,你会看到 ViewContainerRef 对象,检查它的元素属性,你会在那里找到 span。但是,当您将 View 附加到容器中时,它将附加到 span 旁边而不是插入其中,并且 span 将悬空。
关于html - 当 ViewContainerRef 被注入(inject)指令时,它绑定(bind)到什么元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54837892/