Angular 获取模板中包含的所有子组件的宽度
我在模板中有这个标记。我可以使用Angular 获取模板中包含的所有子组件的宽度,angular,typescript,angular9,Angular,Typescript,Angular9,我在模板中有这个标记。我可以使用get遍历它的组件,但是它没有返回一个允许我深入挖掘HTML属性的对象 <ng-template #container></ng-template> c不允许我访问element或nativeElement,因此我可以获得offsetWidth 有没有其他方法可以实现这一点?在强制转换到EmbeddedViewRef后,可以通过使用rootNodes属性来实现: for (var x = 0; x < this.appAsideCo
get
遍历它的组件,但是它没有返回一个允许我深入挖掘HTML属性的对象
<ng-template #container></ng-template>
c
不允许我访问element
或nativeElement
,因此我可以获得offsetWidth
有没有其他方法可以实现这一点?在强制转换到
EmbeddedViewRef
后,可以通过使用rootNodes
属性来实现:
for (var x = 0; x < this.appAsideContainer.length; x++) {
const viewRef = this.appAsideContainer.get(x) as EmbeddedViewRef<any>;
const rootNode = viewRef.rootNodes[0];
console.log(rootNode);
}
for(var x=0;x
for (var x = 0; x < this.appAsideContainer.length; x++) {
const viewRef = this.appAsideContainer.get(x) as EmbeddedViewRef<any>;
const rootNode = viewRef.rootNodes[0];
console.log(rootNode);
}