Finding height of the largest div element and setting it for all div elements Angular 8

后端 未结 1 1760
终归单人心
终归单人心 2021-01-24 23:47

I have a div element that is looped through an array of objects using *ngFor. The height of a particular div is different from each other as each object contains different amoun

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 00:03

    You can use ViewChildren to get the elements, and in ngAfterViewInit, get the size

    {{food.title}}

    {{food.ingredients}}

    @ViewChildren('foodcard') foodCards:QueryList ngAfterViewInit() { let maxHeight=0 this.foodCards.forEach(x=>{ const height=x.nativeElement.getBoundingClientRect().height if (heigth>maxHeight) maxHeight=height }) }

    Anyway, if your aim is set the same height check card-deck

    0 讨论(0)
提交回复
热议问题