Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 获取模板中包含的所有子组件的宽度_Angular_Typescript_Angular9 - Fatal编程技术网

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);
}